Rules for implementing a virtual function Krish Advani 26/04/2013 Engineering When virtual functions are created for implementing late binding, there are some basic rules that satisfy the compiler requirements: The virtual function must be member of some class. They cannot be static members. They are accessed by using object pointer. The virtual function can be friend of another class. A virtual function in a base class must be defined, even though it may not be used. The prototype of the base class version of a virtual function and all the derived class version must be identical. If two function with same name have different prototype, C++ considers them as overloaded functions and virtual function mechanism is ignored. We cannot have virtual constructor, but we can have virtual destructors. While a base pointer can point to any type of the derived object, the reverse is not true. That is, we cannot use a pointer to a derived class to access an object of the base type. When a base pointer points to a derived class, incrementing and decrementing it will not make it point to the next object of desired class. It is incremented or decremented only relative to its base type. Therefor, we should not use this method to move the pointer to the next object. If a virtual function is defined in the base class, it need not be necessarily redefined in the derived class. In such cases, calls will invoke the base function.