这是代码。
#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&lt;&lt; (p-> getTotalNum)&lt;&lt; ENDL; ^
答案 0 :(得分:8)
ul
cout << (p->getTotalNum) << endl;
是一种类方法。因此必须像任何其他函数一样调用它:
getTotalNum