我有一个基类和几个可以有多个实例的派生类。派生类有一个静态字符串,其中存储了国籍名称。看起来像这样...
// Base Class
class Person{
private:
// Informations that every person has. Not depending on the nationality
unsigned char m_size;
char[] m_name;
public:
// Get the human readable name of a nationality
void getNationalityName(char* pNatiName);
}
void Base::getNationalityName(char* pNatiName);
{
strcpy(pNatiName, m_nationalityName);
}
// A derived class
class American : public Person{
private:
unsigned int m_dollar;
static char[] m_nationalityName;
}
// Another derived class
class Russian : public Person{
private:
unsigned int m_rubel;
static char[] m_nationalityName;
}
我现在想使用派生类之一的“getNationalityName”方法访问国籍名称。问题是,基类不知道派生类有一个名为“m_nationalityName”的属性。
我可以在每个类中实现“getNationalityName”方法,但我认为这不是解决这个问题的正确方法。