这是代码。
#include <iostream>
#include <cstring>
using namespace std;
class Headquarter
{
private:
//num of total warriors
int totalNum;
public:
int getTotalNum() ;
};
int Headquarter::getTotalNum()
{ return totalNum; }
int main()
{
Headquarter a;
Headquarter *p =&a;
cout << (p->getTotalNum) << endl;
return 0;
}
我无法使用g ++,4.8.4进行编译。我不知道这是怎么回事。这是错误的消息:
test.cpp: In function ‘int main()’:
test.cpp:19:7: error: no match for ‘operator<<’ (operand types are std::ostream {aka std::basic_ostream<char>}’ and ‘<unresolved>`overloaded function type>’)
cout <<(p-> getTotalNum)<< endl; ^
cout << (p->getTotalNum) << endl;
getTotalNum
是一个类方法。因此,必须像其他任何函数一样调用它:
cout << (p->getTotalNum()) << endl;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句