virtual inheritance

N

Noah Roberts

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

Ron Natalie

Noah said:
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.
 
S

Salt_Peter

Noah said:
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
 
M

Martin Steen

Noah said:
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
 
W

werasm

Noah said:
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
 
N

Noah Roberts

Ron said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top