E
efrenba
Hi,
The problem is in the for statement, I need to identify each elements
of this array as TC1 or TC2 but it doesn't work, the typeid().name()
always returns "TBase".
#include <typeinfo.h>
class __rtti TBase
{
private:
int aAge;
public:
TBase(int pAge = 0) : aAge(pAge) {};
};
class TC1: public TBase
{
private:
char aSex;
public:
TC1(char pSex = 'F', int pAge = 0) : aSex(pSex), TBase(pAge) {};
char getSex() const { return aSex; };
};
class TC2: public TBase
{
private:
float aMoney;
public:
TC2(float pMoney = 0.0, int pAge = 0) : aMoney(pMoney), TBase
(pAge) {};
float getMoney() const { return aMoney; };
};
------------------
TBase *base[3];
TC1 c1('F', 51);
TC2 c2(9.5, 25);
base[0] = &c1;
base[1] = &c2;
base[3] = &c1;
for (int i = 0; i < 3; i++)
ShowMessage(typeid(*base).name());
The problem is in the for statement, I need to identify each elements
of this array as TC1 or TC2 but it doesn't work, the typeid().name()
always returns "TBase".
#include <typeinfo.h>
class __rtti TBase
{
private:
int aAge;
public:
TBase(int pAge = 0) : aAge(pAge) {};
};
class TC1: public TBase
{
private:
char aSex;
public:
TC1(char pSex = 'F', int pAge = 0) : aSex(pSex), TBase(pAge) {};
char getSex() const { return aSex; };
};
class TC2: public TBase
{
private:
float aMoney;
public:
TC2(float pMoney = 0.0, int pAge = 0) : aMoney(pMoney), TBase
(pAge) {};
float getMoney() const { return aMoney; };
};
------------------
TBase *base[3];
TC1 c1('F', 51);
TC2 c2(9.5, 25);
base[0] = &c1;
base[1] = &c2;
base[3] = &c1;
for (int i = 0; i < 3; i++)
ShowMessage(typeid(*base).name());