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. Advertisements

  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. Advertisements

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. Jeremy Bowers
    Replies:
    3
    Views:
    730
    Steven Bethard
    Jan 24, 2005
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    1,372
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,840
    Smokey Grindel
    Dec 2, 2006
  4. Alf P. Steinbach
    Replies:
    6
    Views:
    816
    John Carson
    Sep 3, 2005
  5. alexl
    Replies:
    5
    Views:
    473
    James Kanze
    Apr 14, 2008
  6. Replies:
    4
    Views:
    646
    Zeppe
    Sep 12, 2008
  7. nguillot
    Replies:
    5
    Views:
    926
    itaj sherman
    Feb 24, 2011
  8. Daniel Finnie
    Replies:
    3
    Views:
    369
    Logan Capaldo
    Dec 16, 2006
Loading...