Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: C++
Expertise: Intermediate
Jun 30, 1999

Converting a Virtual Member Function to a Pure Virtual One in a Derived Class

In general, a derived class that inherits a pure virtual member function from its abstract base class implements this function. The opposite is also true: a virtual member function that is implemented in a base class can become pure virtual in a derived class. For example:

class Base
   virtual void func() { /*do something */ }

class Derived : public Base
  virtual void func() = 0; // redefined as pure virtual

You don't normally convert a virtual member function to a pure virtual in a derived class, however, sometimes it is the only way to overcome flaws in a base class that you are not allowed to fix but have to inherit from.

Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date