1.

What are virtual functions and pure virtual functions?

Answer»

A virtual function is a member function that is declared in a BASE class and overridden by a derived class. When we are using a pointer or a reference to the base class to refer to a derived class object, we can invoke a virtual function for that object and have it run the derived class's version of the function.

  • Regardless of the type of reference (or pointer) used for a function call, virtual functions make SURE the RIGHT function is called for an object.
  • They're MOSTLY implemented to accomplish POLYMORPHISM at runtime.
  • The virtual keyword is used to declare functions in base classes.
  • Run-time resolution of function calls is performed.

Functions that are only declared in the base class are known as pure virtual functions or abstract functions. This indicates that they have no definition in the base class and must be redefined in the subclass.



Discussion

No Comment Found