Posted by Hal Bonnin on 2000-02-17
>Subject: MFC: CArray
>
>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?
>_____________________________________________
>Signed: Fox
> sfox@xxxxxxxx.xxx
>
not sure if this helps but i use an array of a class like so:
in the header file.
class Basic_Data
{
private:
char Data[DATASIZE];
char NAME[NAMESIZE];
int Type;
public:
inline char* GetData(){return Data;}
inline void SetData(char* NewData){strcpy(Data,NewData);}
// etc.......
};
class Global_Data
{
public:
Basic_Data Data_Array[DATAARRAYSIZE];
}
at the top of my main cpp file i put this in
Global_Data DATA;
inside the cpp functions i call the array like so
void GameApp::UpDateData(int Where,char* What)
{
DATA[Where].SetData(What);
}
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