473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A question about the diamond inheritance

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
Aug 17 '05 #1
3 2475
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

Aug 17 '05 #2
Tony Johansson wrote:
Hello Experts!!
[snip Tony's query] //Tony


Tony, please go through
http://ozark.hendrix.edu/~burch/csbs...ltinherit.html

That might answer your query.

You would like to move to "alt.comp.lang.learn.c-c++" newsgroup. That
will be more suitable for your queries.

Aug 17 '05 #3
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

Aug 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stephan Diehl | last post by:
I have a question about metaclasses: How would be the best way to "merge" different metaclasses? Or, more precisely, what is the best way to merge metaclass functionality? The idea is basicly...
13
by: John Perks and Sarah Mount | last post by:
Trying to create the "lopsided diamond" inheritance below: >>> class B(object):pass >>> class D1(B):pass >>> class D2(D1):pass >>> class D(D1, D2):pass Traceback (most recent call last): File...
2
by: Tony Johansson | last post by:
Hello Experts!! Here we use multiple inheritance from two classes.We have a class named Person at the very top and below this class we have a Student class and an Employee class at the same...
5
by: Tony Johansson | last post by:
Hello Experts! I just play around just to try to understand this about multiple inheritance. You have all the class definition below and at the bottom you have the main program. So here I...
5
by: Tony Johansson | last post by:
Hello Experts! It it correct to say that a solution to the diamond problem is to use virtual inheritance with virtual base classes. //Tony
2
by: emma middlebrook | last post by:
Hi I come from a C++ background and so am familiar with the 'dreaded inheritance diamond' i.e. the ambiguity of which data to use when a class appears twice in the hierarchy. Here's a link for...
4
by: Pallav singh | last post by:
I am Facing Problem while creating object of Diamond Ring problem solving using Template Kindly let me known where i am committing ERROR Thanks Pallav #include<iostream.h> #include<string.h>
9
by: weird0 | last post by:
How does C++ and C# solve the Diamond problem? With the help of interfaces that is. Can anyone elaborate ....... Regards
6
by: Rocketmagnet | last post by:
Hi all, I have been kind of forced (honestly) into writing a class structure which contains a Diamond of Death, and I'm not entirely sure what to do about it. This is a simplified version of my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.