469,913 Members | 2,638 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

Question on virtual inheritance..

Hi,

sorry if it was already asked,

I have a following class diagram

A =? A
| |
B C
\ /
\ /
D

Now :

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

Will class D have duplicated values from A in such scenerio? I think not.

now, what about this :

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

is it equivalent to the previous code? I mean will class D have duplicated
variables from A?

--
thank you


Jul 22 '05 #1
3 1091
cyrusNew wrote:
sorry if it was already asked,

I have a following class diagram

A =? A
| |
B C
\ /
\ /
D

Now :

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

Will class D have duplicated values from A in such scenerio? I think not.

now, what about this :

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

is it equivalent to the previous code?
No.
I mean will class D have duplicated
variables from A?


Yes.

V
Jul 22 '05 #2

Uzytkownik "Victor Bazarov" <v.********@comAcast.net> napisal w wiadomosci
news:GL*******************@newsread1.mlpsca01.us.t o.verio.net...
cyrusNew wrote:
sorry if it was already asked, <snip> now, what about this :

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

is it equivalent to the previous code?


No.
I mean will class D have duplicated
variables from A?


Yes.

V


thank you, just one more question, Iam thining of changing one class from
plain inheritance (like above class C) to virtual inheritance. Actually this
class C is used in many places in application (many classes inherit from C)
but needs virtual inheritance only with one class (class D), my question is
if this will reduce efficiency or maybe cause code bloat?

Jul 22 '05 #3
cyrusNew wrote:
[...] Iam thining of changing one class from
plain inheritance (like above class C) to virtual inheritance. Actually this
class C is used in many places in application (many classes inherit from C)
but needs virtual inheritance only with one class (class D), my question is
if this will reduce efficiency or maybe cause code bloat?


No. But if you notice anything like that, come back and we'll talk then.

V
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by JKop | last post: by
5 posts views Thread by Tony Johansson | last post: by
3 posts views Thread by marv | last post: by
13 posts views Thread by John Salerno | last post: by
14 posts views Thread by Bruno van Dooren | last post: by
8 posts views Thread by ^MisterJingo^ | last post: by
20 posts views Thread by Daniel | last post: by
7 posts views Thread by Markus Svilans | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.