A question about the diamond inheritance

T

Tony Johansson

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
 
J

Josh Mcfarlane

Tony said:
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
 
M

Masrur Hossain

Tony said:
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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top