Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why Virtual Function?

function virtual
0
Posted

Why Virtual Function?

0

Is to have derived classes inherit a function interface as well as a default implementation. But its not mandatory to redefine in its derived class. A virtual function allows derived classes to replace the implementation provided by the base class (OR) A virtual function allows a base pointer to be used and yet the right derived class function to be called Why should be base class destructor be virtual If you destroy an object through a pointer or reference to a base class and the base class destructor is not virtual then the derived class destructor are not executed and the destruction might not be complete. If not it leads to memory leaks.

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123