Browse DevX
Sign up for e-mail newsletters from DevX

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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
Thanks for your registration, follow us on our social networks to keep up-to-date