Why ambiguous base when one is inherited private?

Discussion in 'C++' started by a eriksson, Aug 9, 2005.

  1. a eriksson

    a eriksson Guest

    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
     
    a eriksson, Aug 9, 2005
    #1
    1. Advertising

  2. a eriksson wrote:
    > 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
     
    Victor Bazarov, Aug 9, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,949
    Smokey Grindel
    Dec 2, 2006
  2. Alf P. Steinbach
    Replies:
    6
    Views:
    549
    John Carson
    Sep 3, 2005
  3. alexl
    Replies:
    5
    Views:
    359
    James Kanze
    Apr 14, 2008
  4. Replies:
    4
    Views:
    475
    Zeppe
    Sep 12, 2008
  5. nguillot
    Replies:
    5
    Views:
    700
    itaj sherman
    Feb 24, 2011
Loading...

Share This Page