multiple inheritance; consistency of 'virtual'

Discussion in 'C++' started by m0shbear, Mar 10, 2011.

  1. m0shbear

    m0shbear Guest

    How come with
    class A{};
    class B: public A{};
    class C: public virtual A, public virtual B{};

    , B needs to virtual inherit A so that ambiguity in C wrt members of A
    can be resolved? Is this due to subtleties of vtable generation when
    MI is used?
    m0shbear, Mar 10, 2011
    #1
    1. Advertising

  2. m0shbear <> wrote:
    > How come with
    > class A{};
    > class B: public A{};
    > class C: public virtual A, public virtual B{};
    >
    > , B needs to virtual inherit A so that ambiguity in C wrt members of A
    > can be resolved? Is this due to subtleties of vtable generation when
    > MI is used?


    Without virtual inheritance there is an ambiguity because both B and
    C inherit from A, while C also inherits from B. If you tried it without
    virtual inheritance, you would get errors like:

    error: 'A' is an ambiguous base of 'C'

    Making C inherit from A makes little sense in this case. If you really
    wanted to do that, for whatever strange reason, it would have to be done
    like this:

    class A {};
    class B: virtual public A {};
    class C: virtual public A, public B {};

    However, the above is just effectively doing the same as:

    class A {};
    class B: public A {};
    class C: public B {};

    just less efficiently.
    Juha Nieminen, Mar 10, 2011
    #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. =?Utf-8?B?VkIgQ29kZXI=?=

    Maintain Consistency With ASP.NET Templates

    =?Utf-8?B?VkIgQ29kZXI=?=, Apr 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    433
    aruntjose
    Feb 13, 2006
  2. qazmlp
    Replies:
    19
    Views:
    779
    Daniel T.
    Feb 4, 2004
  3. cppsks
    Replies:
    0
    Views:
    806
    cppsks
    Oct 27, 2004
  4. Ashwin
    Replies:
    2
    Views:
    340
    Pierre Barbier de Reuille
    Aug 1, 2006
  5. Replies:
    1
    Views:
    455
    Alf P. Steinbach
    Mar 14, 2009
Loading...

Share This Page