Difference between runtime and compile time polymorphism in c++

4.8k Views Asked by At

I'm confused between these two polymorphism please help me out by giving simple examples as a i'm totally new to c++.Give me some basic idea only.

1

There are 1 best solutions below

2
On BEST ANSWER

Polymorphism means writing general code to work with different objects without knowing their exact types.

Static binding is a property that allows the compiler to resolve the type called at compile time. But there can be static binding without polymorphism.The compile time polymorphism is implemented using function and operator overloading where compiler has all the prior knowledge about the data type and no. of arguments needed so it can select the appropriate function at compile time.

Dynamic binding is a property which allows to decide about the type at run time. But there can be dynamic binding without polymorphism. If dynamic binding is used for writing general code which works with objects of several classes in hierarchy then it will be dynamic polymorphism. Run time polymorphism is implemented by virtual functions(a member function declared in base class using keyword virtual which redefined with same name by its derived class).