473,507 Members | 9,962 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

virtual inheritance / dreaded diamond again

Hello,

I want to build up an inheritance structure looking like two coupled dreaded
diamonds. It's similar to an old posting of me. Now my question is, where
to use the keyword virtual.

CV
/ \
/ \
V CDV
\ / \
\ / \
DV CMI
\ /
\ /
MI

I placed virtual like this:

V : public virtual CV
CDV : public virtual CV
DV : public virtual CDV, public V
CMI : public virtual CDV
MI : public DV, public CMI

My porblem is, that the construction process of an MI does not do the
conctructor calls, I would expect. There is a constructor

MI(const CDV &rhs) : DV(rhs) {} // CMI has a default constructor.

which calls

DV(const CDV &rhs) : V(rhs) {} // CDV has a default constructor.

and now I would expect

V(const CV &rhs) {} // CV has a default constructor.

to be called, but actually

V() {}

is called. And here I wonder. Where am I wrong. I hope I provided enough
information. Else ask please. All classes are template classes by the way,
if relevant.

regards,
alex


Jul 19 '05 #1
1 2000

"Alexander Stippler" <st**@mathematik.uni-ulm.de> wrote in message news:3f******@news.uni-ulm.de...

V() {}

is called. And here I wonder. Where am I wrong. I hope I provided enough
information. Else ask please. All classes are template classes by the way,
if relevant.


All virtual base classes are initialized by the most derived object before any
non-virtual bases. It is the constructor of your most derived class (MI) that
needs to pass any arguments to the virtual bases.

MI(const CDV& rhs) : DV(rhs), CV(rhs) { }

or the like.

The order of construction of your heirarchy is:
CV, CDV, V, DV, CMI, MI
Jul 19 '05 #2

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

Similar topics

0
4215
by: Alexander Stippler | last post by:
I've got an inheritance structure with two coupled "dreaded diamonds" like shown below: A / \ / \ B C \ / \ \ / \ D E \ /
2
3585
by: Corno | last post by:
Hi all, I know there are quite a few arguments in favor or against MI. I know there are a lot of usenet discussions about wether MI is actually needed or not. These discussions mention the...
3
1425
by: puzzlecracker | last post by:
I am sure people are familiar with dirty diamond problem solved by virtual inheritance. look at the code below and tell me how many instances of the base class (in this case A) does class D...
4
4591
by: Xavier | last post by:
Hi, I have a question, in a "dreaded diamond" situation, regarding the following code: ---- Begin code #include <iostream> using namespace std;
2
2403
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...
14
1893
by: Bruno van Dooren | last post by:
Hi all, i am having a problems with inheritance. consider the following: class A { public: A(int i){;} };
60
4867
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
7
4867
by: 2005 | last post by:
Hi What is the purpose of declaring a class with a "Virtual" in front? What is the benefit? Thanks
2
2536
by: Paul McGuire | last post by:
On May 25, 8:37 am, Michael Hines <michael.hi...@yale.eduwrote: Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). --...
0
7221
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,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.