David W wrote:
"Thomas J. Gritzan" <Ph************ *@gmx.dewrote:
>Please repeat the question in the body of the posting:
"function overload vs. virtual function"
asdf wrote:
>>They looks so similar. Anybody would like to tell me their differences?
This question makes no sense. Do you confuse overloading with over_writing_?
Confusing overloading with _overriding_ is rather more likely than confusing it with overwriting.
You are right. In german it's overwriting ("überschreiben ").
To the OP:
There is function overloading, function hiding and function overriding.
It's called function overloading when you have functions with the same name
but different signatures:
void foo(int i);
void foo(float f);
The compiler decides by looking at the actual parameter types, which
function is called.
If you have two functions with the same name in two different but enclosing
scopes, it is called function hiding:
namespace outer
{
void foo(int i);
namespace inner
{
void foo(float f);
}
}
In the inner scope, only the void foo(float) gets called, because the outer
function is hidden. The same applies to non-virtual functions or virtual
function with different signature:
class base
{
virtual void foo(int i);
void bar(int i);
};
class sub : public base
{
void foo(float f); // different signature, hides base::foo
void bar(int i); // same signature as in base, but non-virtual, so
hides base::bar
};
Only if you have a virtual function with the same signature, it's called
function overriding, and the function gets called polymorphically .
Hope that's right and clear, and no homework. :-)
--
Thomas
http://www.netmeister.org/news/learn2quote.html