Properties of C++ Virtual Function:

1. A member function of a class
2. Declared with virtual keyword
3. Usually has a different functionality in the derived class
4. A function call is resolved at run-time

The difference between a non-virtual c++ member function and a virtual member function is, the non-virtual member functions are resolved at compile time. This mechanism is called static binding. Whereas the c++ virtual member functions are resolved during run-time. This mechanism is known as dynamic binding. 

C++ Virtual Function - Reasons:- 
The most prominent reason why a C++ virtual function will be used is to have a different functionality in the derived class.

Rules for virtual functions: 

When virtual functions are created for implementing late binding, we should observe some basic rules that satisfy the compiler requirements.
1. The virtual functions must be member of the same class
2. They cannot be static members
3. They are accessed by using object pointers
4. A virtual function can be a friend of another class.

Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment: