Posted by Frank Hale on 2000-02-15
> I have this class called: > > class CFeatureRect : public CRect > > > CFeatureRect has a few classes derived from it, > defined below: > > class CLine : public CFeatureRect > class CEllipse : public CFeatureRect > etc... > > Is it possible to have a CArray object like this: > > CArray<CFeatureRect, CFeatureRect &> shape; > > .and then store a CLine, or a CEllipse object on > this array? > > shape.SetAtGrow(0, CLine(...)); > > > In other words, is it legal, safe and usable, to > store derived classes on an > array defined to hold their base classes? > > If this is possible, can I access any data fields, > functions, etc; that are on the > stored derived class but aren't on the base class > and vice versa? Is everything > accessable when I store a derived class on there? This sounds very interesting. I am not a Windows(tm) programmer, but I have done something very similar in X Windows on a Unix system. I am writing a Window Manager and I have a class which represents a client application. The number of class objects during execution can vary and I am constantly adding and removing them as needed. I store all these objects inside a linked list. The linked list uses templates to store any type you desire. This class holds alot of data and has many member functions. This linked list is really good and fast. Its simple to find and retrieve the classes you want which are stored in it. The linked list code is Ansi code so it should be cross platform. It is really easy to use and I don't see why you couldn't adapt it to use for a windows program. If by chance you are interested let me know and I will send you the code. Sorry I didn't exactly give you an answer you were requesting. Oh and about your question pertaining to "Is everything accessable when I store a derived class on there?", the answer is yes it is with the linked list code I have. Frank ===== ICQ: 7205161 http://sapphire.sourceforge.net - Another X11 Window Manager __________________________________________________ Do You Yahoo!? Talk to your friends online with Yahoo! Messenger. http://im.yahoo.com To signoff send a mail to listserver@xxxx.xx.xx with "signoff tcg" in the body of your message.
Previous post | Next post | Timeline | Home