Click to See Complete Forum and Search --> : Ambigous!!! But why???


aqueel
January 28th, 2005, 09:03 AM
If I have

class Base1 {
public:
int myFunc();
};

class Base2 {
public:
void myFunc();
};

class Derived: public Base1, // Derived doesn't declare
public Base2 { // a function called doIt
...
};
Derived d;
d.myFunc(); // error! — ambiguous
That fine No probs

but when I have
class Base1 {
public:
int myFunc();
};

class Base2 {
private:
void myFunc(); // this function is now
}; // private
class Derived: public Base1, public Base2
{ ... }; // same as above

Derived d;
int i = d.myFunc(); // error! — still ambiguous!

The call to myFunc() continues to be ambiguous, even though only the function in Base1 is accessible!
Why do we have such behaviour??

Thanx for ur response in advance.

cilu
January 28th, 2005, 09:18 AM
The compiler detects ambiguities by performing tests in this order:

If access to the name is ambiguous, an error message is generated.
If overloaded functions are unambiguous, they are resolved.
If access to the name violates member-access permission, an error message is generated.

The names are checked before the access permission.

You can get rid of it by using:

Derived d;
int i = d.Base1::myFunc();

NMTop40
January 28th, 2005, 09:45 AM
You can also get rid of it using "using"

class Derived : public Base1, public Base2
{
public:
using Base2::myFunc();
};