This is the code.
#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;
}
I can't compile it with g++,4.8.4. I don't konw what's wrong with it. This is the wrong message:
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
is a class method. Therefore it must be invoked like any other function:
cout << (p->getTotalNum()) << endl;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.