这是代码。#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 ^ 最佳答案 cout << (p->getTotalNum) << endl;getTotalNum是一个类方法。因此,必须像其他任何函数一样调用它:cout << (p->getTotalNum()) << endl;关于c++ - 我在C++中的代码有什么问题?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32643168/
10-11 18:12