By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

name collisions in multiple inheritance

P: n/a
Vam
my compiler doesn't compile the following:

struct Base1
{
virtual void F(){}
};

struct Base2
{
virtual void F(){}
};

struct Derived : public Base1, private Base2
{
}

int main()
{
Derived d;
d.F();

return 0;
}

It complains that F is ambiguous. But when I try to do

d.Base2::F();

it notices that Base2 is private and hence inaccessible. Is my compiler
broken in this regard? I know I can use 'using base1::F()' in my derived
class, or 'd.Base1::F()' in main(), but it surprises me that I have to.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Vam

"Vam" <ie@explorem.com> wrote in message
news:37*************@individual.net...
my compiler doesn't compile the following:

struct Base1
{
virtual void F(){}
};

struct Base2
{
virtual void F(){}
};

struct Derived : public Base1, private Base2
{
}

int main()
{
Derived d;
d.F();

return 0;
}

It complains that F is ambiguous. But when I try to do

d.Base2::F();

it notices that Base2 is private and hence inaccessible. Is my compiler
broken in this regard? I know I can use 'using base1::F()' in my derived
class, or 'd.Base1::F()' in main(), but it surprises me that I have to.


Just some minor corrections, add a ; after the Derived struct declaration,
and the 'using base1::F' shouldn't have the trailing ().
Jul 23 '05 #2

P: n/a
Vam wrote:
my compiler doesn't compile the following:

struct Base1
{
virtual void F(){}
};

struct Base2
{
virtual void F(){}
};

struct Derived : public Base1, private Base2
{
}

int main()
{
Derived d;
d.F();

return 0;
}

It complains that F is ambiguous. But when I try to do

d.Base2::F();

it notices that Base2 is private and hence inaccessible. Is my compiler
broken in this regard?


No. In C++ access specifications have no effect on name resolution. The
"privateness" of 'Base2::F' does not prevent it from participating in
name resolution process. In other words, the compiler first tries to
resolve the name and only then starts to pay attention to the access
rights. In your case name 'F' is indeed ambiguous.

--
Best regards,
Andrey Tarasevich
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.