472,794 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 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 1166
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.