472,958 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

oop inheritance graph

a
Hi,
I have an oop inheritance graph problem.
What is the difference betweent the following 2 inheritance graph?
How does the C++ solve the naming conflict problem for multiple inheritance
problem?

Thanks

A
/ \
B C
\ /
D
A A
| |
B C
\ /
D
Jun 25 '07 #1
5 3466
On Jun 24, 11:25 pm, "a" <a...@mail.comwrote:
Hi,
I have an oop inheritance graph problem.
What is the difference betweent the following 2 inheritance graph?
How does the C++ solve the naming conflict problem for multiple inheritance
problem?

Thanks

A
/ \
B C
\ /
D

A A
| |
B C
\ /
D
There is no difference between the two graphs that you draw since both
B and C inherit from A in both graphs. You have to use "virtual
inheritance" for class A. Scott Meyers discusses this point in detail
in his book Effective C++ (item 43). You may want to avoid this kind
of inheritance graph. The naming convention is defined by the closest
definition of a function to D. For example, if A defines foo() and
this is redefined in C, D uses the C version of foo(). Hope it helps.

Jun 25 '07 #2
a wrote:
Hi,
I have an oop inheritance graph problem.
What is the difference betweent the following 2 inheritance graph?
How does the C++ solve the naming conflict problem for multiple inheritance
problem?

Thanks

A
/ \
B C
\ /
D
A A
| |
B C
\ /
D

Please see:
http://www.parashift.com/c++-faq-lit...heritance.html

--
Sumit Rajan <su*********@gmail.com>
Jun 25 '07 #3
On Jun 25, 6:25 am, "a" <a...@mail.comwrote:
I have an oop inheritance graph problem.
What is the difference betweent the following 2 inheritance graph?
How does the C++ solve the naming conflict problem for multiple inheritance
problem?
A
/ \
B C
\ /
D

A A
| |
B C
\ /
D
In the first, you only have a single instance of A; both B and C
have the same instance as their base class. In the second, you
have two instances. In C++, you use virtual inheritance to
achieve the first, e.g.:

First:

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

Second:

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

Note the presence of the keyword "virtual" in the inheritance in
the first.

I'm not too sure what you mean by "naming conflict". In the
first, there is only one instance of each class, so there is no
ambituity when referring to a base class. In the second, in D
(or when using an object of type D), any direct reference to A
is ambiguous, since the compiler doesn't know which one; to
disabmiguate, first refer to B or C, e.g. B::A::... or C::A::...

--
James Kanze (GABI Software, from CAI) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 25 '07 #4
aaragon wrote:
On Jun 24, 11:25 pm, "a" <a...@mail.comwrote:
>Hi,
I have an oop inheritance graph problem.
What is the difference betweent the following 2 inheritance graph?
How does the C++ solve the naming conflict problem for multiple inheritance
problem?

Thanks

A
/ \
B C
\ /
D

A A
| |
B C
\ /
D

There is no difference between the two graphs that you draw since both
B and C inherit from A in both graphs. You have to use "virtual
inheritance" for class A. Scott Meyers discusses this point in detail
in his book Effective C++ (item 43). You may want to avoid this kind
of inheritance graph. The naming convention is defined by the closest
definition of a function to D. For example, if A defines foo() and
this is redefined in C, D uses the C version of foo(). Hope it helps.
No, you don't "have to" use virtual inheritance. That's the difference
between them: the top one uses it and the bottom one doesn't.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Jun 25 '07 #5
a

"James Kanze" <ja*********@gmail.com>
???????:11**********************@n2g2000hse.google groups.com...
On Jun 25, 6:25 am, "a" <a...@mail.comwrote:
I have an oop inheritance graph problem.
What is the difference betweent the following 2 inheritance graph?
How does the C++ solve the naming conflict problem for multiple
inheritance
problem?
A
/ \
B C
\ /
D

A A
| |
B C
\ /
D
In the first, you only have a single instance of A; both B and C
have the same instance as their base class. In the second, you
have two instances. In C++, you use virtual inheritance to
achieve the first, e.g.:

First:

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

Second:

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

Note the presence of the keyword "virtual" in the inheritance in
the first.

I'm not too sure what you mean by "naming conflict". In the
first, there is only one instance of each class, so there is no
ambituity when referring to a base class. In the second, in D
(or when using an object of type D), any direct reference to A
is ambiguous, since the compiler doesn't know which one; to
disabmiguate, first refer to B or C, e.g. B::A::... or C::A::...

--
James Kanze (GABI Software, from CAI) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Thank you for your reply.
The naming conflict may occur between B and C, since they both inherited
from A. Both B and C have the properties inherited from A, and they have the
same name. So, naming conflict may occurs. I understand the purpose of the
keyword "virtual". But, in terms of "instance", what is the difference
between class B : public virtual A {} and class B : public A {}?

Thanks

Jun 26 '07 #6

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

Similar topics

4
by: T. Kaufmann | last post by:
Hi there, A simple but important question: How can I initialize a super class (like dict) correctly in my subclass constructor? A sample: class MyClass(dict): def __init__(self):
9
by: Lilith | last post by:
Is there a python module somewhere (been searching today, no luck) which has efficiently coded various graph-handling routines, such as finding the shortest path through a graph, or the set of all...
2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
14
by: Axel Straschil | last post by:
Hello! Im working with new (object) classes and normaly call init of ther motherclass with callin super(...), workes fine. No, I've got a case with multiple inherance and want to ask if this...
1
by: Nicola | last post by:
Consider the following implementation of a graph, whose nodes must be of type Node or of a subclass of Node: class Node { public: Node(Data* d) { adjList = new vector<Node*>; data = d; }...
10
by: jeffc | last post by:
When compiling the following program, I get an error on the line specified: The base class "B" cannot be initialized because it does not have a default constructor. If I remove the "virtual"...
8
by: Michael J. Fromberger | last post by:
Consider the following class hierarchy in Python: class A (object): def __init__(self): print "cons A" class B (object): def __init__(self): print "cons B"
12
by: Massimo | last post by:
Hi to all, I'm facing a problem in a particularly complex inheritance hierarchy, and I'd like to know what the standard says about it and if my compiler is correct in what it does. I have two...
4
by: EnsGabe | last post by:
Suppose you have a class heirarchy as such: class Base{ .... }; class Mid1 : public Base{ ....
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.