Virtual functions
Inherit methods and member of parent classes.
Virtual functions in C++ are a key feature of object-oriented programming that enable polymorphism. Here's a concise explanation:
Definition: A virtual function is a member function declared in a base class and redefined in derived classes.
Purpose: They allow a program to call methods of a derived class through a pointer or reference of the base class type.
Declaration: Declared using the 'virtual' keyword in the base class.
Late binding: The function call is resolved at runtime, not compile-time.
Pure virtual functions: Defined with "= 0" and make the class abstract.
Virtual destructors: Often used to ensure proper cleanup of derived objects.
Virtual table (vtable): C++ uses this behind the scenes for implementation.
Run it here.
Last updated