473,396 Members | 1,799 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,396 software developers and data experts.

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 2435
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
0
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...
0
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
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,...

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.