[comp.sys.mac.programmer] Multiple Inheritance in Think C

soudan@iitmax.iit.edu (Bassel Soudan) (03/12/91)

Hello fellow mail list patrons,

	I have a problem that I am trying to solve and I need your help.

	The problem has to do with multiple inheritance and goes like this:

	I created a CComponent class to model a hardware component. Each
component is made up of several elements (Panes, Buttons, StaticText etc.).
The elements for the components are grouped together in a List called
itsElements. When my component receives a Draw or Move message, I want to
pass that along to all the elements that make up this component. Here is what I
am doing now :

	In my CComponent::Draw() method I call

	DoForEach->itsElements(DrawElem);

	In DrawElem (CObject *obj) 	I try to do the following :

	obj->Draw();			All the elements that make up the
					components have a Draw message defined.

	When I try to compile this program, I get the famous "Draw is not part
of the struct or union" or something similar to that. I get this because CObject
does not have a Draw method (and it shouldn't).

	What I want to do is create a co-parent class for all the objects that
will be elements in my components, so that I can cast obj into that and solve
the problem. The elements that I am using are all subclasses that I derived 
from the original classes. (for example I derived a CField class as a sub-class
of CPane).

	I created a sub-class of CObject and made all my element classes 
sub-classes of that class. The only problem is that my element classes no
longer exhibit the behavior of their original parents. (i.e. my CField which
should be working like a CPane is no longer able to perform any of the things
that a CPane can).

	I asked this quetion somewhere else, and somebody suggested that I
create a subclass of CObject (call it Element for now) and then customize
it by pointing to instances of a CPane or a CButtonor or whatever. The only
problem is that my customized instance of CElement will not inherit all the
behavior of the parent class (the one whose instance I am pointing to).

	The whole problem is that I need to cast the entries in the itsElements
list to be able to pass them the Draw message that I got. If anyone knows a way
to bypass this casting requirement, that might solve my problem.

	I am sorry if this has been long and confusing but this is the only
way I could describe the problem. If you can be of any assistance I would be
eternally gratefull.

			Sincerely yours,

			Bassel Soudan

			soudan@iitmax.iit.edu
-- 
________________________________________________________________________________

	"Learn to say I don't know, and not to say I know.
	 Because, if you say 'I don't know' the people will teach you
	 until you know, and if you say 'I know' the people will ask
	 you until you don't know."

________________________________________________________________________________

Lawson.English@p88.f15.n300.z1.fidonet.org (Lawson English) (03/14/91)

Bassel Soudan writes in a message to All

BS> The whole problem is that I need to cast the entries in the itsElements

BS> list to be able to pass them the Draw message that I got. If 
BS> anyone knows a way to bypass this casting requirement, that might 
BS> solve my problem

Are all of your elements sub-classes of CPane? If so, just cast them to CPane.
If not, well, why not? All the ones that you mentioned are? Is there a special
reason not to have them all CPane-based?


Lawson
 

--  
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!300!15.88!Lawson.English
Internet: Lawson.English@p88.f15.n300.z1.fidonet.org