Virtual function in c++
Virtual Function: Virtual means existing in effect but not in reality. A type of function that appears to exist in some part of the program but does not exist really is called a virtual function. Virtual functions are used to implement polymorphism. They enable the user to execute completely different functions by the same function call. A virtual function is defined in the parent class and is overridden in child classes. It is defined by the keyword virtual. If you want to call a virtual function in C++ and execute the redefined version of the member function, you can achieve this task using a pointer or a reference ( -> ) by referring a derived class object to the base class. A base class pointer has the capability to point to the objects of the base class and the derived class. But it's converse is not true. An example of using virtual function with reference: #include<iostream> using namespace std; class Animal { public: virtual ...