Question on virtual inheritance..

C

cyrusNew

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?
 
V

Victor Bazarov

cyrusNew said:
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
 
C

cyrusNew

Uzytkownik "Victor Bazarov said:

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?
 
V

Victor Bazarov

cyrusNew said:
[...] 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top