Pure virtual function - Virtual keyword and function

Q.  Pure virtual function is used
- Published on 19 Oct 15

a. to give meaning to derived class function
b. to give meaning to base class function
c. to initialize all functions
d. None

ANSWER: to give meaning to base class function
 
When we use virtual keyword our base class function becomes meaningless as it has no use. It only helps in calling all derived class functions of same name. If base class function is initialized with =0, it is known that function has no body and thus the virtual function of base class becomes pure virtual function.

For example:

class geom
{
public:
virtual void show( )=0;
};

class rect: public geom
{
void show( )
{
cout << " the area is : y" << endl;
}
}

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)