473,738 Members | 2,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

virtual inheritance

Is there anything that says that if you virtually inherit from one
class you have to virtually inherit from anything you inherit from?

Oct 19 '06 #1
5 2472
Noah Roberts wrote:
Is there anything that says that if you virtually inherit from one
class you have to virtually inherit from anything you inherit from?
No, if not if I understand your question. You can (and typically do)
have a mix of virtual and non-virtual inheritance.
Oct 20 '06 #2
Noah Roberts wrote:
Is there anything that says that if you virtually inherit from one
class you have to virtually inherit from anything you inherit from?
What? Can you ask your question with an example?
Your question can be answered ad infinitum and public inheritance is
not the same as virtual public inheritance, either.

I see a misconception here. Inheritance does not mean append or attach.
It means transpose or redesign from scratch. How the redesign takes
place depends on what member functions are virtual and which ones are
virtually overridden or even overloaded.
Also, a ctor and dtor can never be inherited, but a d~tor's vituality
is inherited.

Note that composition is far more common than public inheritance -
which is a strict relationship. If you are trying to circumvent
inheritance of virtual member functions, chances are that the base
class should be a member. Hence the term: composition.

Peter

Oct 20 '06 #3

Noah Roberts wrote:
Is there anything that says that if you virtually inherit from one
class you have to virtually inherit from anything you inherit from?
What are you actually asking - whether virtual iheritance is carried
over??? e.g.

struct Base{};
struct Derived1 : virtual Base{};
struct Derived2 : Derived{};

Derived 2 automatically inherits virtually from Base, as this is
implied because Derived1 does. Derived2 though, does not automatically
inherit virtually from Derived1.

see C++ std 98 par. 10.1/4

Regards,

Werner

Oct 20 '06 #4
Noah Roberts wrote:
Is there anything that says that if you virtually inherit from one
class you have to virtually inherit from anything you inherit from?
No. Only methods with the "virtual"-keyword are virtual inherited. All
other methods are normal inherited.

-Martin
Oct 20 '06 #5

Ron Natalie wrote:
Noah Roberts wrote:
Is there anything that says that if you virtually inherit from one
class you have to virtually inherit from anything you inherit from?
No, if not if I understand your question. You can (and typically do)
have a mix of virtual and non-virtual inheritance.
Yes, you understand my question. I'm getting very strange results I
hadn't gotten until I tried virtual inheritance on one class. It is
affecting a different parent. I didn't think virtual inheritance
required that but it was worth asking because I have no idea what is
going on.

Thread on that is titled "Anyone seen anything like this" or something
like that. I'll be trying to reproduce it in a simple program today if
I can.

Oct 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
2223
by: nenad | last post by:
Wouldn't it be nice if we could do something like this: class Funky{ public: auto virtual void doStuff(){ // dostuff } };
4
2901
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 {}
14
1922
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){;} };
3
1710
by: Imre | last post by:
Hi! I've got some questions regarding heavy use of virtual inheritance. First, let's see a theoretical situation, where I might feel tempted to use a lot of virtual inheritance. Let's suppose, we're creating a little strategy game. In our game, there are Units. A Unit can be either a Human, or a Vehicle. Obviously, Human and Vehicle are subclasses of Unit.
3
4550
by: kikazaru | last post by:
Is it possible to return covariant types for virtual methods inherited from a base class using virtual inheritance? I've constructed an example below, which has the following structure: Shape = base class Triangle, Square = classes derived from Shape Prism = class derived from Shape TriangularPrism, SquarePrism = classes derived from Triangle and Prism, or Square and Prism respectively
12
2661
by: mijobee | last post by:
I'm very new to c++ and just writing some code to learn. I've run into a problem, with a javaish design, and want to know if there is any possible solution without modifying the design. I've read up on virtual inheritance and from my understanding this should work fine but I haven't found any docs that use such a tangled example. The gcc output containing the errrors: Example.cpp: In member function 'virtual IObject*...
5
1989
by: toton | last post by:
Hi, I want a few of my class to overload from a base class, where the base class contains common functionality. This is to avoid repetition of code, and may be reducing amount of code in binary, not to get polymorphic behavior. None of them has virtual methods, and are self contained (no destructor at all) thus do not have a chance to have memory error. Thus the derived classes has additional functionality, not additional data.
23
4612
by: Dave Rahardja | last post by:
Since C++ is missing the "interface" concept present in Java, I've been using the following pattern to simulate its behavior: class Interface0 { public: virtual void fn0() = 0; };
12
2379
by: Massimo | last post by:
Hi to all, I'm facing a problem in a particularly complex inheritance hierarchy, and I'd like to know what the standard says about it and if my compiler is correct in what it does. I have two consecutive layers of diamond-shaped inheritance; the first layer is declared as using virtual inheritance, while the second one is declared as *not* using it. This is what I'd like to have:
0
1315
by: =?Utf-8?B?Zmplcm9uaW1v?= | last post by:
Hi all, As I mentioned in a previous thread (see 'Dbghelp, symbols and templates' in microsoft.public.windbg), we created a powerful symbol engine using dbghelp to dump the contents of the stack symbols when an exception occurs. The engine is able to dereference and process UDT symbols up to their highest base class. It also supports multiple inheritance. However, we are having trouble with virtual inheritance. Documentation is very...
0
8787
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,...
0
9473
Oralloy
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...
0
9334
jinu1996
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...
1
9259
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,...
0
9208
tracyyun
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...
0
6053
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();...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.