Top "Virtual-functions" questions

In object-oriented programming, a virtual function or virtual method is a function or method whose behaviour can be overridden within an inheriting class by a function with the same signature.

Mechanism of Vptr and Vtable in C++

In C++, during dynamic binding, consider the following example... class Base { virtual void fun() { cout<<"Base"; } }; class Derived : …

c++ virtual-functions dynamic-binding
Use-cases of pure virtual functions with body?

I recently came to know that in C++ pure virtual functions can optionally have a body. What are the real-world …

c++ virtual-functions
Should I default virtual destructors?

I have an abstract class that is declared as follow: class my_type { public: virtual ~my_type() = default; virtual void …

c++ c++11 destructor virtual-functions
Overriding public virtual functions with private functions in C++

Is there is any reason to make the permissions on an overridden C++ virtual function different from the base class? …

c++ overriding access-control virtual-functions
C++ header file and function declaration ending in "= 0"

I have the following code inside the .h file and I'm not sure what does the assignment statement do and …

c++ virtual-functions
Why use base class pointers for derived classes

class base{ ..... virtual void function1(); virtual void function2(); }; class derived::public base{ int function1(); int function2(); }; int main() { derived d; …

c++ oop polymorphism virtual-functions base-class
C++ Pointer to virtual function

If you have a struct like this one struct A { void func(); }; and a reference like this one A& …

c++ function-pointers virtual-functions member-function-pointers
When is a vtable created in C++?

When exactly does the compiler create a virtual function table? 1) when the class contains at least one virtual function. OR 2) …

c++ polymorphism virtual-functions vtable
What's the point of a final virtual function?

Wikipedia has the following example on the C++11 final modifier: struct Base2 { virtual void f() final; }; struct Derived2 : Base2 { void …

c++ c++11 inheritance final virtual-functions
What are the differences between overriding virtual functions and hiding non-virtual functions?

Given the following code fragment, what are the differences in the function calls? What is function hiding? What is function …

c++ inheritance virtual-functions overriding method-hiding