Why ambiguous base when one is inherited private?

A

a eriksson

Why is the call foo(c) below ambiguous when B inherits A privately? I
think that that contradicts the first error reported below since B
objects are not treated as A objects?

class A {};

class B : private A {};

class C : public B, public A {};

void foo(A& a) {}

int main() {
B b;
// foo(b); error: `A' is an inaccessible base of `B'
C c;
foo(c); // error: `A' is an ambiguous base of `C'
}

/ Andreas
 
V

Victor Bazarov

a said:
Why is the call foo(c) below ambiguous when B inherits A privately? I
think that that contradicts the first error reported below since B
objects are not treated as A objects?

class A {};

class B : private A {};

class C : public B, public A {};

void foo(A& a) {}

int main() {
B b;
// foo(b); error: `A' is an inaccessible base of `B'
C c;
foo(c); // error: `A' is an ambiguous base of `C'
}

Overload resolution happens before checking access privileges.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top