CHAPTER OUTLINE
CHAPTER SEVEN
POLYMORPHISM AND DYNAMIC BINDING
-4 HOURS
7.1 Need of Virtual Function
7.2 Pointer to Derived Class
7.3 Definition of Virtual Functions
7.4 Array of Pointers to Base Class
7.5 Pure Virtual functions and Abstract Class
7.6 Virtual Destructor
7.7 reinterpret cast Operator
7.8 Run‐Time Type Information
7.8.1 Dynamic cast Operator
7.8.2 Typeid Operator
REVIEW MATERIAL(OBJECT POINTER)
The syntax of for declaring the object pointer is:
class_name *pointer_name;
When the object pointer points to another object, the members of the
object can be accessed by the object pointer through the use of ->
operator.
Example:
student s;
student *ptr;
ptr=&s;
In this situation we can write ptr->name, ptr->roll, ptr-
>marks, ptr->address in place of s.name, s.roll,
s.marks and s.address.
Moreover the object pointer can invoke the member function with the ->
operator in place of dot operator. For example:
ptr->getdata();
ptr->showdata();
can be written in place of
s.getdata();
s.showdata();
Polymorphism
→ Polymorphism is another important OOP concept.
→ Polymorphism(Poly = many, morph = form), a Greek term, means the
ability to take more than one form.
→ An operation may exhibit different behavior in different instances. The
behavior depends upon the types of data used in the operation.
For example: consider the operation of addition. For two numbers, the
operation will generate a sum. If the operands are strings, then the
operation would produce a third string by concatenation.
→ The process of making an operator to exhibit different behaviors in
different instances is known as operator overloading.