Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Virtual functions ensure that the correct function is called for an object, regardless of the type of reference (or pointer) used for function call.
Parent* p = new Child(); p->show(); // If show() is virtual, Child's version runs. // If NOT virtual, Parent's version runs.
virtual void draw() = 0;Makes a class "Abstract". You cannot create objects of an abstract class. It forces derived classes to implement the function.
Under the hood, C++ uses a Virtual Table (vtable) and a Virtual Pointer (vptr) to perform runtime dispatching. This adds a tiny overhead to function calls.