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 3 1213
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
Uzytkownik "Victor Bazarov" <v.********@com Acast.net> napisal w wiadomosci
news:GL******** ***********@new sread1.mlpsca01 .us.to.verio.ne t... 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?
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 there shouldn't have been a
"virtual" keyword for this purpose, but instead, a "nonvirtual" keyword!
In teaching inheritance, you see the common example:
class Vehicle {}
|
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 use multiple inheritance.
One top class called MBase and below this we have D1 and D2 on the same
level.
|
by: marv |
last post by:
If I have abstract base classes like these:
//---------
class IBase
{
public:
virtual void Action(void) = 0;
};
|
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 includes.
My question is, if you must declare each method (as opposed to simply
'using' those methods like an #included file), then why not just
declare the methods on your own as if you created them yourself? What
advantage does using an interface...
|
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){;}
};
| |
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 the individual elements in an
array of ImageList's could be identified by the ID, thereby allowing
re-ordering the array without harm. A person could identify by index into
the array, but that would not be preserved by re-ordering (and re-ordering...
|
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
{
|
by: Daniel |
last post by:
I have the following three classes
class A
{
public:
virtual void f() = 0;
};
class B: public A
{
|
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 BufferBase, and
customized in order to be able to a type of data (of any kind, such as
chunks of audio samples from a sound card). The processor classes are
derived from ProcessorBase, and are customized to handle
BufferBase-derived objects. Each...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |