[英]What's wrong with my code in c++?
这是代码。
#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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.