13.6 PURE VIRTUAL FUNCTIONS

If you believe that, the idea of virtual function has solved the problem. You are mistaken. Actually, the situation can be described as “akash se fisle Aur khajoor pe atke” (escaped from the sky and hung on a tree, meaning escaped from a big trouble but caught in a small trouble).

Imagine a case where you forget to declare (and define) a function move in any derived class object. If base class pointer is pointing to this object and you invoked move(), the computer will execute the base class move(). This is quite unacceptable. What is the solution? Pure virtual functions!

Most of the times, the idea behind of declaring a function (in the base class) virtual, is to stop its execution. Then the question arises why should ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.