A question about the diamond inheritance

Discussion in 'C++' started by Tony Johansson, Aug 17, 2005.

  1. Hello Experts!!

    Assume you have the following diamond inheritance structure.
    Assume the following at the top you have the Ancestor class and below this
    class
    at the same level we have class Child1 and Child2.
    Class Descendatnt is derived class Child1 and Child2.
    Assume also that in the top class we have one datamember called number and
    one method called getNumber(). If you don't use virtual inheritance you will
    get compile error.
    Assume you get compile error because of not using virtual inheritance.

    Now to my question is it corrext to say that in class Descendant you will
    get two
    subobjects of class Ancestor one from Child1 and the other from Child2.

    Or is it more correct to say that the datamember number will appear in the
    Descendats twice because of
    being inheritaded twice one from class Child1 and the other inheritaded from
    class Child2.
    The same will happen with the method getNumber you will have two one from
    Child1 and one from Child2

    //Tony
     
    Tony Johansson, Aug 17, 2005
    #1
    1. Advertising

  2. Tony Johansson wrote:
    > Assume you have the following diamond inheritance structure.
    > Assume the following at the top you have the Ancestor class and below this
    > class
    > at the same level we have class Child1 and Child2.
    > Class Descendatnt is derived class Child1 and Child2.
    > Assume also that in the top class we have one datamember called number and
    > one method called getNumber(). If you don't use virtual inheritance you will
    > get compile error.
    > Assume you get compile error because of not using virtual inheritance.
    >
    > Now to my question is it corrext to say that in class Descendant you will
    > get two
    > subobjects of class Ancestor one from Child1 and the other from Child2.


    Depends on where you use the virtual inheritance. If you use it
    properly on the definition of Child1 & Child2, you will only have 1
    Ancestor subobject.

    Judging from the amount of questions you've posted, you may want to
    consider switching to another book that is easier to understand.

    Josh McFarlane
     
    Josh Mcfarlane, Aug 17, 2005
    #2
    1. Advertising

  3. Tony Johansson

    Jaspreet Guest

    Jaspreet, Aug 17, 2005
    #3
  4. Tony Johansson wrote:
    > Hello Experts!!
    >
    > Assume you have the following diamond inheritance structure.
    > Assume the following at the top you have the Ancestor class and below this
    > class
    > at the same level we have class Child1 and Child2.
    > Class Descendatnt is derived class Child1 and Child2.
    > Assume also that in the top class we have one datamember called number and
    > one method called getNumber(). If you don't use virtual inheritance you will
    > get compile error.
    > Assume you get compile error because of not using virtual inheritance.
    >
    > Now to my question is it corrext to say that in class Descendant you will
    > get two
    > subobjects of class Ancestor one from Child1 and the other from Child2.
    >
    > Or is it more correct to say that the datamember number will appear in the
    > Descendats twice because of
    > being inheritaded twice one from class Child1 and the other inheritaded from
    > class Child2.
    > The same will happen with the method getNumber you will have two one from
    > Child1 and one from Child2
    >
    > //Tony
    >
    >
     
    Masrur Hossain, Aug 21, 2005
    #4
    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. Alexander Stippler

    virtual inheritance / dreaded diamond problem

    Alexander Stippler, Jul 14, 2003, in forum: C++
    Replies:
    0
    Views:
    1,892
    Alexander Stippler
    Jul 14, 2003
  2. Alexander Stippler

    virtual inheritance / dreaded diamond again

    Alexander Stippler, Aug 26, 2003, in forum: C++
    Replies:
    1
    Views:
    398
    Ron Natalie
    Aug 26, 2003
  3. Tom
    Replies:
    3
    Views:
    509
  4. John Perks and Sarah Mount

    MRO problems with diamond inheritance?

    John Perks and Sarah Mount, May 1, 2005, in forum: Python
    Replies:
    13
    Views:
    611
    Michele Simionato
    May 3, 2005
  5. Victor Bazarov

    diamond inheritance, constr. question

    Victor Bazarov, Jan 13, 2006, in forum: C++
    Replies:
    4
    Views:
    351
    =?iso-8859-1?q?Stephan_Br=F6nnimann?=
    Jan 14, 2006
Loading...

Share This Page