Object Oriented Programming - C++
Polymorphism - C++
The ability of an object to exist in many forms
Polymorphism is achieved through inheritance and dynamic binding
The backbone to Polymorphism is the concept of virtual functions and pointers
Virtual function
A member function is declared virtual in a base class using the keyword,
virtual
<>B>
It is defined in a base class, and is redefined in a derived class
The keyword virtual is not repeated in the derived class
A virtual function is not an overloaded function
Virtual functions are inherited in a derived class
A virtual function must be defined in the class in which it was declared
A virtual function must be a member function of a class, and not a friend function
A virtual function cannot be a static function member
Constructor functions cannot be virtual functions
Destructor functions can be virtual functions
Pure Virtual function
A virtual function that is not defined in the base class in which it was declared
It is made pure by initializing it to zero
The format is:
virtual RT function( … ) = 0;
Abstract Class
A class in which at least one pure virtual function is declared
It is illegal to define an object of an abstract class
Exception Handling & Inheritance
If a throw is made by a derived class a match for an exception of handler of the base class is automatically made
Exception class is better handled using virtual functions
When a throw is made, the catch argument must be a reference parameter rather than value parameter
Multiple Inheritance
Go Back