How to implement the runtime polymorphism using c++. examples.

Showing Answers 1 - 3 of 3 Answers

AvinashChaturvedi

  • Aug 3rd, 2006
 

Hi To All,

    First We Know that polymorphism means "Single interface Multiple Methods" so whenever we want to implement this into our program we use it in form of function overloading and operator overloading but these both perform static or compile time polymorphism so for the runtime polymorphism we must perform these operations

 1 . implement a base class with some functions with virtual keyword on witch u want to perform polymorphism

 2. implement a drived class from this base class and also implement all the functions on which u want to perform polymorphism here a important point is that the signature of all the functions must be same in base and drived classes but virtual keyword not used in drived class.

3. implement a  programe which you create a reference for base class and an object for base class. an object for drived class also created .

4. now on the runtime if u store the address of base class object into the ref of base class then function defination from base class will be called and when ref contain an address of drived class object it called the drived class version for that function.

Regards,

Avinash chaturvedi ( Avi )  

    

  Was this answer useful?  Yes

ripon07

  • Jul 13th, 2010
 

First We Know that Polymorphism means Single Interface Multiple Methods so whenever we want to implement this into our program we use it in form of function overloading and operator overloading but these both perform static or compile time polymorphism so for the runtime polymorphism we must perform these operations

1. Implement a base class with some functions with virtual keyword on which you want to perform polymorphism

2. Implement a drived class from this base class and also implement all the functions on which you want to perform polymorphism here a important point is that the signature of all the functions must be same in base and drived classes but virtual keyword not used in drived class.

3. Implement a programe which you create a reference for base class and an object for base class. an object for drived class also created .

4. Now on the runtime if you store the address of base class object into the ref of base class then function defination from base class will be called and when ref contain an address of drived class object it called the drived class version for that function.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions