This is overloading, not polymorphism. The compiler can tell which version to call from the parameter types. Think of it like it is generating internally 2 functions Double_int and Double_long (this would be how you would have to do it were there no overloading in C++) then when it sees a call to Double with a long parameter, it calls Double_long, and the same w/ int. Original is the name of the parameter, just like if you had int Double(int n), the return would be return 2*n;

The best definition of polymorphism that I've heard is that it's when one piece of code can be executed for different datatypes. In that case if you wrote

Code:

template<class T>
T Double(T original)
{
return 2 * original;
}

People refer to this as static polymorphism because it is done at compile time. It will most likely generate the same two function calls you had above, kind of begging the question of what the code for your function is.

function overloading is also called function polymorphism, i understand what the prog is doing, but not how is doing it. how does it know that original which is not defined anywhere has 2 different values in different types, when int double is called and when long double is called, original has a different value.

you compiler compiles your code and sees that you have 2 functions declared with the same name, it checks to make sure all of the syntax is correct and then makes a note in its memory for later that there are two functions with the same name.

Now, when you call function Double, depending on what you pass to the function, the compiler will automatically choose which function to call. For example, if you did Double((int)34) it would call the integer version of the function, but if you called Double((long)34) it would call the long version.

This is polymorphism. The draw function is redefined in each class - object knows how to draw object and square knows how to draw square.

The compiler will call Square::Draw when called from objects of type square...

...and will call Object::Draw when called from objects of type Object.

However, calling function overloading the same as function polymorphism...yeah....I'll buy it because I see the point....but polymorphism is more than that.

There is also something else at work here. Object could theoretically call the draw function of all who derive from it. So to draw an object you could simply call one function which would draw each object instead of having to call square->draw(), circle->draw(), etc. But that's for another thread.