473,503 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

virtual hell

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 receive?
class A
{
:
:

};
class B: virtual public A {

:
:

};
class C: virtual public A {

:
:

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

:
:

};
====

A small follow up: is inheritance by default public, protected or
private such class A: B{};?
what is the difference between
class A
{
:
:

};
class B: virtual public A {

:
:

};
class D:public B {

:
:

};
OR

class D: virtual public B {
:
:

};
============
Next: can you inline the virtual functions? is the behavior undefined,
nonstandard, etc?

Jul 22 '05 #1
17 1205
puzzlecracker wrote:
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 receive?
class A
{
};

class B: virtual public A {
};

class C: virtual public A {
};

class D: public B, public C, virtual public A {
};
One. All instances of deriving from 'A' are virtual.

BTW, you really need to conserve whitespace. If we go about wasting
whitespace like you did in your post, we may run out of it sooner than
we think.
====

A small follow up: is inheritance by default public, protected or
private such class A: B{};?
Default is private for classes, public for structs.
what is the difference between
class A
{
};

class B: virtual public A {
};

class D:public B {
};

OR
AND
class D: virtual public B {
};
There is no difference. In both cases 'A' is a virtual base class and
has to be constructed in 'D'. In both cases 'B' is a direct base class
of 'D' and has to be constructed in 'D'.
============
Next: can you inline the virtual functions? is the behavior undefined,
nonstandard, etc?


I can. The behaviour is just fine.

V
Jul 22 '05 #2
Thanks so much Victor.

just a little small one:
One. All instances of deriving from 'A' are virtual


but how is it done that that only one instance exists in the subclass
when the derivation is virtual... I just can visualize the process that
takes place behind the scene... any ideas?

Jul 22 '05 #3
Thanks so much Victor.

just a little small one:
One. All instances of deriving from 'A' are virtual


but how is it done that that only one instance exists in the subclass
when the derivation is virtual... I just can visualize the process that
takes place behind the scene... any ideas?

Jul 22 '05 #4
back to that diamond problem: Why is it so that when derivation is
virtual from base class, only one instance exist, as in the first
example?
thx

Jul 22 '05 #5
puzzlecracker wrote:
Thanks so much Victor.

just a little small one:

One. All instances of deriving from 'A' are virtual

but how is it done that that only one instance exists in the subclass
when the derivation is virtual... I just can visualize the process that
takes place behind the scene... any ideas?


I am not sure what kind of help I could offer. The compiler knows all the
base classes, the entire hierarchy, when it compiles the 'D' class. It
has to come up with a layout of the class. It merges all instances of any
class inherited virtually into one, and all those that are not inherited
virtually, get left where they are. If you had left at least one of the
'A' derivations non-virtual, you'd have another instance of 'A' hanging
around in the 'D' object.

V
Jul 22 '05 #6
WOw, thx.
now real basic stuff. so when you inherit from the class...subclass
phsycially has all of its protected and public methods just as he has
is own? But why then it hides overloaded methods of base class?

Jul 22 '05 #7
puzzlecracker wrote:
back to that diamond problem: Why is it so that when derivation is
virtual from base class, only one instance exist, as in the first
example?


Because the language definition says so.
Jul 22 '05 #8
puzzlecracker wrote:
now real basic stuff. so when you inherit from the class...subclass
phsycially has all of its protected and public methods just as he has
is own? But why then it hides overloaded methods of base class?


Because the language definition says so.
Jul 22 '05 #9
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:OI*******************@newsread1.mlpsca01.us.t o.verio.net...

BTW, you really need to conserve whitespace. If we go about wasting
whitespace like you did in your post, we may run out of it sooner than
we think.


Lots of snow at my place. You're welcome to some or all
of it if you run out of whitespace and need a substitute.
(but you must pay for shipping).

:-)

-Mike
Jul 22 '05 #10
Now it is off the topic.... I read 3 or C++ books, such as C++ primer,
C++ design revealed, and standard template library... what is your
prime choice of C++ books? Want to see if that would shift my paradigm
towards better practices.

Thanks... I know, I Know it is way off the topic.. but in the need of
your opinion, guidance.

Many thanks

Jul 22 '05 #11
Now it is off the topic.... I read 3 or C++ books, such as C++ primer,
C++ design revealed, and standard template library... what is your
prime choice of C++ books? Want to see if that would shift my paradigm
towards better practices.

Thanks... I know, I Know it is way off the topic.. but in the need of
your opinion, guidance.

Many thanks

Jul 22 '05 #12
"puzzlecracker" <ir*********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Now it is off the topic.... I read 3 or C++ books, such as C++ primer,
C++ design revealed, and standard template library... what is your
prime choice of C++ books? Want to see if that would shift my paradigm
towards better practices.

Thanks... I know, I Know it is way off the topic.. but in the need of
your opinion, guidance.


IMO asking about C++ learning materials is topical here.

Have you consulted the FAQs, and the book reviews
at www.accu.org ?

C++ FAQ:
http://www.parashift.com/c++-faq-lite/

FAQ for newsgroup alt.comp.lang.learn.c-c++:
http://www.comeaucomputing.com/learn/faq/

Do you have the 'bible', Stroustrup's "The C++ Programming Language"?

-Mike
Jul 22 '05 #13
puzzlecracker wrote:
Now it is off the topic....
It's not, actually...
I read 3 or C++ books, such as C++ primer,
C++ design revealed, and standard template library... what is your
prime choice of C++ books? Want to see if that would shift my paradigm
towards better practices.


Nowadays I read different books than when I was just starting with C++.
And different people respond differently to the way C++ is presented
in different books, so, I'll recommend to go to a book store and read
a few pages from the beginnings of several books. Make sure you read
the preface and the foreword. There the authors often say what the
intended readership is. The main purpose of that exercise is to see if
you're comfortable with the way the author presents the material and
with the material itself.

Of course, there are books that are highly recommended, and Mike already
gave you the link to the ACCU site. Follow it. You don't have to buy
and read all book that are marked "highly recommended", but at least you
will get an idea (or print out a list) of what or whom to prefer/avoid
when you actually get in the store.

Also, books have come up frequently here over the years, so do check out
the newsgroup archives for that.

Also, do not limit yourself to reading only C++ books. The application
domain is usually more important to be fluent in than the language in
which you implement the application. It never hurts to be fluent in the
language, but don't make it the only goal. Let it become a side effect
of using the language. Use caution when reading C++ examples and what-
not in non-C++ books. Some authors tend to pay less attention to the
language than to the application domain (and that's the RIGHT THING(tm))
just try not to pick up their bad habits.

Good luck!

V

P.S. Hey, I managed not to name a single book here...
Jul 22 '05 #14
Mike Wahler wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:OI*******************@newsread1.mlpsca01.us.t o.verio.net...
BTW, you really need to conserve whitespace. If we go about wasting
whitespace like you did in your post, we may run out of it sooner than
we think.

Lots of snow at my place. You're welcome to some or all
of it if you run out of whitespace and need a substitute.


Do you think your substitute idea is gonna hold water?
(but you must pay for shipping).

:-)

:-)
Jul 22 '05 #15

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:XR*******************@newsread1.mlpsca01.us.t o.verio.net...
Mike Wahler wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:OI*******************@newsread1.mlpsca01.us.t o.verio.net...
BTW, you really need to conserve whitespace. If we go about wasting
whitespace like you did in your post, we may run out of it sooner than
we think.

Lots of snow at my place. You're welcome to some or all
of it if you run out of whitespace and need a substitute.


Do you think your substitute idea is gonna hold water?


In some climates, and for some applications, such as control
programs for refrigeration systems.

I also have a small quantity of yellow snow available for a
nominal additional fee.

:-)

-Mike
Jul 22 '05 #16
Mike Wahler wrote:
BTW, you really need to conserve whitespace. If we go about wasting
whitespace like you did in your post, we may run out of it sooner than
we think.

Lots of snow at my place. You're welcome to some or all
of it if you run out of whitespace and need a substitute.
(but you must pay for shipping).


And when Stroustrup's proposal for witespace overloading will be included in
the standard, It will work for snow or we must to also overload snow?

--
Salu2
Jul 22 '05 #17

"Julián Albo" <JU********@terra.es> wrote in message
news:34*************@individual.net...
Mike Wahler wrote:
BTW, you really need to conserve whitespace. If we go about wasting
whitespace like you did in your post, we may run out of it sooner than
we think. Lots of snow at my place. You're welcome to some or all
of it if you run out of whitespace and need a substitute.
(but you must pay for shipping).


And when Stroustrup's proposal for witespace overloading will be included

in the standard, It will work for snow or we must to also overload snow?


I don't think such overloading would be practical,
as it would most likely produce an avalanche of bugs.

-Mike
Jul 22 '05 #18

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

Similar topics

11
1969
by: Dave Rudolf | last post by:
Hi all, Suppose that I have a class (let's call the class A) with a virtual method. I then define a subclass (B), which could potentially be extended by some other subclass (say, C). So, A <- B...
4
2702
by: DaKoadMunky | last post by:
I was recently looking at some assembly code generated by my compiler. When examining the assembly code associated with constructors I noticed that the dynamic-dispatch mechanism was enabled...
14
2031
by: rogerclive | last post by:
Perhaps, there is no bigger sleazy company in the entire Maple Republic ( Canada ) than Matrox Graphics Inc. I paid $100+ through my nose circa 1999 for Matrox Millenium II and Mystique. It...
26
3945
by: pmizzi | last post by:
When i compile my program with the -ansi -Wall -pedantic flags, i get this warning: `class vechile' has virtual functions but non-virtual destructor, and the same with my sub-classes. But when i...
10
7273
by: Martin Vorbrodt | last post by:
Example code in one of my books intrigues me: class B { public: B* Clone() const { B* p = DoClone(); assert(typeid(*p) == typeid(*this)); return p; }
28
5170
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
2
1228
by: Griff | last post by:
Rather new to this.... I've created a new web site using VS 2005. It's created the files under my "documents and settings" area and the URL to this site is http://localhost:3066/website1 I...
20
1977
by: Daniel | last post by:
I have the following three classes class A { public: virtual void f() = 0; }; class B: public A {
4
5104
by: wally | last post by:
There is a brilliant application that allows you to wrap your EXE and all associated DLLs, OCXs, etc. into a single executable and run the executable on Windows OSs with no install and nor...
0
7202
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
7086
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
7330
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...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
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
5014
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
3167
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
380
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.