View Single Post
  #2 (permalink)  
Old April 3rd, 2020, 04:38 AM
ankitdixit ankitdixit is offline
Registered User
 
Join Date: Sep 2019
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In the aforementioned program bp is a pointer of type Base. A call to bp->show() calls show() function of the Derived class. This is because bp points to an object of the Derived class.

Things essential to writing a virtual function in C++ are:

1. A base class
2. A derived class
3. A function with the same name in both the classes i.e. the base class and the 4. derived class
5. A pointer or reference of base class type that points or refers, respectively to an object of the derived class

Now i have clear about virtual functions in C++, thanks to this post. It's very useful and helpful.
Reply With Quote