A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class.
C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. C++ virtual function is,
* A member function of a class * Declared with virtual keyword * Usually has a different functionality in the derived class * A function call is resolved at run-time
Above answer was rated as good by the following members: ozkan, amavi
C++ virtual function is a member function of a class whose functionality can be over-ridden in its derived classes. C++ virtual function is
* A member function of a class * Declared with virtual keyword * Usually has a different functionality in the derived class * A function call is resolved at run-time
C++ virtual functions are used to acheive run time polymorphism. To declare a virtual function virtual keyword is put at the start of normal function declaration. Requirements for implementing virtual function- [/LIST] * Base Class Pointer * Inheritance * Method Overriding.
It is a functions whose behaviour can be overriden with an inherited class by a function of same signature. It is an important part of OOPS and Polymorphism.