473,473 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Create 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 2443
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
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
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...
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){;} };
3
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...
3
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...
12
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...
5
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,...
23
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
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...
0
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.