473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1191
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that...
5
by: Tony Johansson | last post by:
Hello Experts! I just play around just to try to understand this about multiple inheritance. You have all the class definition below and at the bottom you have the main program. So here I...
3
by: marv | last post by:
If I have abstract base classes like these: //--------- class IBase { public: virtual void Action(void) = 0; };
13
by: John Salerno | last post by:
Hi all. I have a question about interfaces now. According to the book I'm reading, when you implement an interface, the class or structure has to declare all the methods that the interface...
14
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){;} };
6
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that...
8
by: ^MisterJingo^ | last post by:
Hi all, I have a question regarding inheritance. I'll use the following code for an example (its been stripped down to the minimum): // code start using System; class Animal {
20
by: Daniel | last post by:
I have the following three classes class A { public: virtual void f() = 0; }; class B: public A {
7
by: Markus Svilans | last post by:
Hello, My question involves virtual functions and inheritance. Suppose we have a class structure, that consists of "data" classes, and "processor" classes. The data classes are derived from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...

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.