S
Steve Edwards
Hi,
I'm trying to find a simple way to identify which of a heirachy of
classes a particular class is:
class Agent
{
public:
enum { class_ID = 'Agnt' };
Agent();
virtual ~Agent(){};
virtual string ClassID();
protected:
};
//----------------------------
string Agent::ClassID()
{
char id[4] = {(char)(class_ID>>24), (char)(class_ID>>16),
(char)(class_ID>>8), (char)class_ID };
string strID(id, 4);
return strID;
}
//----------------------------
This works, and returns as a string the class_ID "Agnt"
But then I declare subclasses, such as:
class SubAgent : public Agent
{
public:
enum { class_ID = 'SubA' };
(SubAgent);
virtual ~ SubAgent(){};
protected:
};
Now if I examine SubAgent's class_ID in the debugger I can see that it
has the correct id = 'SubA'. But if I try to retreive it via ClassID(),
I get the Super Class's id of "Agnt".
Is the only solution to re-declare and cut'n'paste a copy of ClassID()
for each of the many sub-classes I have?
Or is there just a better way to do this altogether?
Thanks
Steve
I'm trying to find a simple way to identify which of a heirachy of
classes a particular class is:
class Agent
{
public:
enum { class_ID = 'Agnt' };
Agent();
virtual ~Agent(){};
virtual string ClassID();
protected:
};
//----------------------------
string Agent::ClassID()
{
char id[4] = {(char)(class_ID>>24), (char)(class_ID>>16),
(char)(class_ID>>8), (char)class_ID };
string strID(id, 4);
return strID;
}
//----------------------------
This works, and returns as a string the class_ID "Agnt"
But then I declare subclasses, such as:
class SubAgent : public Agent
{
public:
enum { class_ID = 'SubA' };
(SubAgent);
virtual ~ SubAgent(){};
protected:
};
Now if I examine SubAgent's class_ID in the debugger I can see that it
has the correct id = 'SubA'. But if I try to retreive it via ClassID(),
I get the Super Class's id of "Agnt".
Is the only solution to re-declare and cut'n'paste a copy of ClassID()
for each of the many sub-classes I have?
Or is there just a better way to do this altogether?
Thanks
Steve