【发布时间】:2018-02-28 18:48:41
【问题描述】:
我无法识别此代码的问题...
这是类声明:
class PersonType{
public:
PersonType();
PersonType(string n, int id, string bd);
private:
string name;
int ID;
string birthday;};
这就是问题所在:
PersonType family[20], newBaby("Anny Dube", 20180912, "2 Sept");
//family initialized here
for (int i = 0; i < 20; i++)
if (family.birthday[5] == newBaby.birthday)
cout << family.name[5] << " share a birthday with " << newBaby.name;
我在运行代码时遇到了他的错误:
错误:请求'family'中的成员'birthday',它是非类类型'PersonType [20]'|
错误:请求“family”中的成员“name”,它是非类类型“PersonType [20]”|
我知道姓名、ID 和生日是私密的这一事实是一个问题,但我知道如何解决这个问题。即使我将变量公开或使用访问器方法,我仍然会遇到这两个错误...
我已经阅读了一大堆与此问题相关的问题,但我能找到的都是关于指针、拼写错误的变量等。
似乎对此没有任何帮助......
请帮忙?
【问题讨论】: