Programming with Passion

Make the best out of everything.

Friday, 8 April 2016

What do you mean by pure virtual functions in C++?

What do you mean by pure virtual functions in C++? Give an example?

Pure virtual function is a function which doesn't have an implementation and the same needs to be implemented by the the next immediate non-abstract class. (A class will become an abstract class if there is at-least a single pure virtual function and thus pure virtual functions are used to create interfaces in c++).

How to create a pure virtual function?
A function is made as pure virtual function by the using a specific signature, " = 0" appended to the function declaration as given below,

  1. class SymmetricShape {
  2. public:
  3. // draw() is a pure virtual function.
  4. virtual void draw() = 0;
  5. };

No comments:

Post a Comment