错误完整为:
1>D:\software\VisualStudio\workspace\Project8\Project8\hero.cpp(32,44): error C3867: “Hero::GetMaxLife”: 非标准语法;请使用 "&" 来创建指向成员的指针
主要错误为:error C3867: “Hero::GetMaxLife”: 非标准语法;请使用 "&" 来创建指向成员的指针
找个半天才发现,原来是少个括号了,当成指针了:
ostream& operator<<(ostream& out, const Hero& hero) {
cout << "昵称" << hero.GetNikeName() << "\n";
cout << "等级" << hero.GetLevel() << "\n";
//错误地方,hero.GetMaxLife 后面少了括号
cout << "最大生命" << hero.GetMaxLife << "\n";
cout<<"当前生命"<< hero.GetCurrLife()<<endl;
return out;
}
修改为:
cout << "最大生命" << hero.GetMaxLife() << "\n";