Professional Documents
Culture Documents
When you refer to a derived class object using a pointer of base class, you can call a virtual function
for that object and execute the derive class version for it.
Virtual function ensures the correct version of function is called for an object, regardless the type of
pointer used for function call. The resolving of function is done at Run time so that is why it is called
Run time Polymorphism.
Example
Defining in a base class a virtual function, with another version in a derived class, signals to the
compiler that we don't want static linkage for this function.
What we do want is the selection of the function to be called at any given point in the program to be
based on the kind of object for which it is called. This sort of operation is referred to as dynamic
linkage, or late binding.
A pure virtual function (sometimes called abstract function) is a virtual function which don’t have
any implementation. It is only declared in base class. A pure virtual function is declared by assigning
0 in declaration.
Example