F
Fred
What does the standard say about which overloaded function to match in
this situation:
(Assume classes A and B are defined, and there is an overloaded
operator defined
const A& operator = (const void *);
class Base {
public:
A a;
B b;
virtual void fun( A a& );
virtual void fun( B *b, int i=0 );
};
class Sub : public Base {
void fun( A a);
void fun( B *b, int i=0);
};
Then somewhere I make this call:
A a = new A();
B b = new B();
Sub *s = new Sub();
s->fun( b );
Should it i:
1) invoke Sub's function fun(A)
2) Base's function fun(B,int) with i defaulted to 0
3) fail with no match
gcc gives me option 1
However, if I remove Sub's 2-argument version,
I get option (3)
this situation:
(Assume classes A and B are defined, and there is an overloaded
operator defined
const A& operator = (const void *);
class Base {
public:
A a;
B b;
virtual void fun( A a& );
virtual void fun( B *b, int i=0 );
};
class Sub : public Base {
void fun( A a);
void fun( B *b, int i=0);
};
Then somewhere I make this call:
A a = new A();
B b = new B();
Sub *s = new Sub();
s->fun( b );
Should it i:
1) invoke Sub's function fun(A)
2) Base's function fun(B,int) with i defaulted to 0
3) fail with no match
gcc gives me option 1
However, if I remove Sub's 2-argument version,
I get option (3)