Thursday, February 4, 2010

C++ polymorphism Questions

What is polymorphism?

Polymorphism is the ability to provide single interface to multiple implementation it may be for an or function in different ways. Polymorphism gives different meanings or functions to the operators or functions. A single function usage or an operator functioning in many ways can be called polymorphism. Polymorphism refers to codes, operations or objects that behave differently in different contexts.
There are two types of polymorphism
1. Compile Time Polymorphism ( Static Polymorphism )
2. Run Time Polymorphism (Dynamic Polymorphism )

1. Compile time polymorphism

Compile time polymorphism is a term that refers to C++ template programming. For example, at compile time you determine the actual type of a std::vector by what it contains:

std::vector  vi;
std
::vector std::string> vs;

or function Overloading is the example of compile time polymorphism

2. Run Time Polymorphism (Dynamic Polymorphism )
Virtual function is the example of Run Time polymorphism . At the run time base class pointer decide whether to call the base class function or the derived class function.



No comments:

Post a Comment