Multiple Inheritance Classes

I have a class called NC_PROTO_TELNET, that handles all telnet protocols. Thing is, beside that there are NC_TELNET_MSP, NC_TELNET_MXP and NC_TELNET_MCP. These classes control the actual special protocols. I want to declare NC_PROTO_TELNET with inheritance from all of these protocols. how would I do that?

For example:

Disclaimer: I know this doesn't work, but it illustrates my point

Class NC_PROTO_TELNET: public NC_TELNET_MSP: public NC_TELNET_MXP: public NC_TELNET_MCP
[505 byte] By [ccubed] at [2007-11-20 9:47:37]
# 1 Re: Multiple Inheritance Classes
Class NC_PROTO_TELNET: public NC_TELNET_MSP, public NC_TELNET_MXP, public NC_TELNET_MCP{
/*

*/
}

In ur explanation replace : by , . Then it will work fine. Is it all u want to know?
Mavens at 2007-11-9 1:22:41 >
# 2 Re: Multiple Inheritance Classes
Yeah, that's it. Just wanted an easy way to fold the special protocols into the base protocol and this is what I thought of.
ccubed at 2007-11-9 1:23:39 >
# 3 Re: Multiple Inheritance Classes
Be aware of the diamond problem ( http://en.wikipedia.org/wiki/Diamond_problem) that can arise.

http://www.parashift.com/c++-faq-lite/multiple-inheritance.html
cilu at 2007-11-9 1:24:49 >
# 4 Re: Multiple Inheritance Classes
Oh, that won't happen. NC_TELNET_PROTO is the only class that inhereits from the other three and the other three don't inhereit from anything. So I shouldn't have that problem.
ccubed at 2007-11-9 1:25:49 >
# 5 Re: Multiple Inheritance Classes
Sorry, my bad, then. I must have misread you initial post.
cilu at 2007-11-9 1:26:48 >
# 6 Re: Multiple Inheritance Classes
Isn't that upside down? Would it not be better for NC_PROTO_TELNET to be an abstraction of the other three, and those others to be implementations of it?

Do the MSP, MXP and MCP classes all have entirely different interface (i.e. no non-private member functions in common)? If they share interface, then doing it this way, you'll hit the Siamese twin problem, and anyway, shared interface suggests that the PROTO class should be and abstraction, not a derivative.
Graham at 2007-11-9 1:27:47 >
# 7 Re: Multiple Inheritance Classes
Just a funny way to drive Graham's point home....

In the book by Stroustrup, "The Design and Evolution of C++", on the chapter about multiple inheritance, he gave the rational for the notion as a quote from some message board (if memory serves correctly) with:

"Because I have both a father and a mother."

Right, so, be careful not to let an object marry it's sister!

The kids just don't come out right :)
JVene at 2007-11-9 1:28:53 >
# 8 Re: Multiple Inheritance Classes
I just thought I'd point you to an article that I had written which highlighted some of the pitfalls of multiple inheritance.
MI is not Mission Impossible ( http://www.dev-archive.com/cpp/cpp/string/general/article.php/c13005/)
Some of the comments by DaMagic were also extremely helpful.
angelorohit at 2007-11-9 1:29:48 >
# 9 Re: Multiple Inheritance Classes
Isn't that upside down? Would it not be better for NC_PROTO_TELNET to be an abstraction of the other three, and those others to be implementations of it?

Do the MSP, MXP and MCP classes all have entirely different interface (i.e. no non-private member functions in common)? If they share interface, then doing it this way, you'll hit the Siamese twin problem, and anyway, shared interface suggests that the PROTO class should be and abstraction, not a derivative.

In my opinion from the little I know, I agree with you Graham. I think that the NC_PROTO_TELNET class from what he describes should be an abstract base class that shares an interface for the other protocols, and then to handle any one of these protocols seamlessly, a proxy class that holds a pointer to a NC_PROTO_TELNET object, which could point at the derived class objects. :D

In fact, this design pattern is very OOP, and is very useful. So useful, I have got some real big thoughts as to why the programmers of the standard libraries do not follow this design pattern.

You think about OOP in terms of abstraction, polymorphism, encapsulation, blackboxing, etc... The list goes on and on. However, if you take a look at the design pattern mentioned, you take advantage of "IS A" and polymorphism where the proxy class calls the virtual functions. :cool:
JamesSchumacher at 2007-11-9 1:30:46 >
# 10 Re: Multiple Inheritance Classes
Well, normally it would, but, NC_PROTO_TELNET is the base class. All Telnet terminals will be able to interact with my program through NC_PROTO_TELNET, it's the stuff like IAE,WILL,WON'T, etc. However, within Telnet, are muds, and muds have special protocols developed for them. So, MCP(really MCCP Shortened), MSP, and MXP are specialty protocols. I won't always be using them, in fact, probaly 80% of the time, they won't be used. So i've made NC_PROTO_TELNET the main class because it's the things that will be used most, that being the IAE, WILL, WON'T, etc.

Edit to answer Graham's Question: No. They share no common non-private interfaces. The MSP class contains /only/ that needed to work with the Mud Sound Protocol, the MCCP class contains /only/ that needed to work with the Mud Client Compression Protocol, and MXP contains /only/ that needed to work with the Mud eXtension Protocol. NC_PROTO_TELNET is responsible for recognizing that one of these is being used and then use it.
ccubed at 2007-11-9 1:31:52 >
# 11 Re: Multiple Inheritance Classes
OK. Fair enough.
Graham at 2007-11-9 1:32:56 >