Pure Virtual Functions


  • A virtual function that is declared but not defined in a base class is referred to as a pure virtual function. Here is the general syntax for declaring a pure virtual function: virtual type function_name(parameter_list)=0; virtual void display( )=0;
  • Now when the base class uses a PURE virtual function, each descendent must override that function, or you will get a compile error. This makes sense, because the function has to be defined somewhere.
  • Here's another definition for you: If a class contains a pure virtual function, that class is called an abstract class.
  • Because there is no definition for the function, you cannot create an object of that class. You can however, declare pointers to it.
  • Think of an abstract class as a general class that lays the foundation for descendent classes that define their own methods. This is the heart of polymorphism - let each class define its own operation.
    Example


Call Mechanism << Previous

Next >> Templates

Our aim is to provide information to the knowledge seekers. 

comments powered by Disqus


Footer1