Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!wuarchive!decwrl!shlump.nac.dec.com!shodha.dec.com!tpwest.enet.dec.com!kramer From: kramer@tpwest.enet.dec.com Newsgroups: comp.lang.c++ Subject: Restricting Type of Member in Subclass possible? Message-ID: <1342@shodha.dec.com> Date: 6 Jun 90 19:56:08 GMT Sender: news@shodha.dec.com Reply-To: kramer@tpwest.enet.dec.com () Organization: Digital Equipment Corporation Lines: 28 Hi there! Here is a beginners question: Assume I have a class Node and a class Tree. Tree has a protected member: Node * p. Now I like to add some functionality without changing Nodes and Trees. I like to add some marking stuff to Node, so I create a DerivedNode class with a function mark(). And I want to be able to mark Trees which consist entirely of DerivedNode instances, so I create a DerivedTree with function mark(). Inside DerivedTree:mark() I call p->mark() Sure enough, the compiler complains because *p is of type Node, and I did not want to define Node::mark(). What I would like to do is to state that for DerivedTrees *p is of type DerivedNode. Which is alright since DerivedNode is a subclass of Node (so all stuff defined in Tree would still work). Is there any way of doing that? Should I restructure my abstractions? (if so, how? (What if Node and Tree are library classes?)) Thanks a lot!!!! axel