Non mumber function can be delcared multiple times while member function can only be declared once? Is this right ? My example seems saying yes.
But Why ?
class Base{
public:
int foo(int i);
//int foo(int i=10); //error C2535: 'void Base::foo(int)' : member function already defined or declared
};
//but it seems ok to declare it multiple times
int foo(int i);
int foo(int i=10);
int foo(int i)
{
return i;
}
int main (void)
{
int i = foo();//i is 10
}
From the Standard (2003), §8.3.6/4 says,
Example from the Standard itself:
The second declaration adds default value!
Also see §8.3.6/6.
And an interesting (and somewhat related) topic:
And §9.3/2,
Hope that helps.