我有一个名为 Person 的类:
class Person {
string name;
long score;
public:
Person(string name="", long score=0);
void setName(string name);
void setScore(long score);
string getName();
long getScore();
};
在另一堂课中,我有这个方法:
void print() const {
for (int i=0; i< nPlayers; i++)
cout << "#" << i << ": " << people[i].getScore()//people is an array of person objects
<< " " << people[i].getName() << endl;
}
这是人们的宣言:
static const int size=8;
Person people[size];
当我尝试编译它时,我得到了这个错误:
IntelliSense: the object has type qualifiers that are not compatible with the member function
在 print 方法中的 2 people[i]下面有红线
我究竟做错了什么?