difference between polymorphism and overloading

I found there has many definition about polymorphism and overloading. Some people said that overloading is one type of polymorphism. While some people said they are not the same. Because only one function will be allocate in overloading. While the polymorphism need allocate the memory for each redefined member function. I really feel confusion about this, any one could explain this for me? Further, whether overloading happens at compile time while the polymorphism happens at running time?


Solution 1:

Polymorphism is the process to define more than one body for functions/methods with same name.

Overloading IS a type of polymorphism, where the signature part must be different. Overriding is another, that is used in case of inheritance where signature part is also same.

No, it's not true that polymorphism happens in runtime. What happens in runtime is called runtime polymorphism. That is implemented using virtual keyword in C++.

Hope it helped..

Solution 2:

The polymorphism is the base of the OOP, the overloading is one of ways to implement to polymorphism, specially when are involved operators. More generally, speaking about polymorphism when there are two or more classes involved. While the overloading can be made also inside the same class, we can overload the name of a method with several signatures (different list of parameters). While overriding is designed exclusively for involving two or more classes. Note that the overrided methods have all the same signature.

Solution 3:

this was told by Bjarne Stroustrup in his book,polymorphism is one which a single thing that act in many forms (i.e) A single function that act in many forms with different parameters. since in c++ constructor name have to be same as class name, you cant have different constructors with different name. so to overcome that function overloading came. many people confuse that function overloading is a type of of polymorphism. they are both at different ends they cant be tied together.