A question on multiple-inheritance and its usefullness

M

mike

Hello fellow C++ experts,
is there any dramatic difference between multiple inheritance:

struct MyType4 : MyType1, MyType2, MyType3 {
int MyInt;
};

and:

struct MyType4 {
MyType1 MyObject1;
MyType2 MyObject2;
MyType3 MyObject3;
int MyInt;
};

?

Is just neat sintactic sugar, or is there something that is impossible
to be achieved with the 2nd solution?

I mean, a function accepting a pointer to MyType2 can accept also a
pointer to a MyType4 object, and that's neat, but I could always pass
&MyObject4.MyObject2 to that function (2nd solution without multiple
inheritance), producing the same result (at least I think). Hence my
question "Is just neat sintactic sugar, or..".

Thanks,
Mike
 
M

mlimber

Hello fellow C++ experts,
is there any dramatic difference between multiple inheritance:

struct MyType4 : MyType1, MyType2, MyType3 {
int MyInt;
};

and:

struct MyType4 {
MyType1 MyObject1;
MyType2 MyObject2;
MyType3 MyObject3;
int MyInt;
};

?

Is just neat sintactic sugar, or is there something that is impossible
to be achieved with the 2nd solution?

I mean, a function accepting a pointer to MyType2 can accept also a
pointer to a MyType4 object, and that's neat, but I could always pass
&MyObject4.MyObject2 to that function (2nd solution without multiple
inheritance), producing the same result (at least I think). Hence my
question "Is just neat sintactic sugar, or..".

You can't implement virtual functions for MyTypes 1-3 in MyType4
without inheritance. Check out:

http://www.parashift.com/c++-faq-lite/multiple-inheritance.html#faq-25.4

Cheers! --M
 

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
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top