Tuesday 21 April 2015

Rules for Virtual Functions

? When a virtual function in a base class is created, there must be definition of the virutal function in the base       class even if base class version of the function is never actually called. However pure virtual functions are       exceptions.
? They cannot be static members.
? They can be a friend function to another class.
? They are accessed using object pointers.
? A base pointer can serve as a pointer to a derived object since it is type-compatible whereas a derived          object pointer variable cannot serve as a pointer objects.
? Its prototype in a base class and derived class must be identical for the virtual function to work properly.
? The class cannot have virtual constructors, but can contain virtual destructor. It is possible to have virtual        operator overloading.
? More importantly, to realize the potential benefits of virtual functions supporting runtime polymorphism,          they should be declared in the public section of a class.

No comments:

Post a Comment