我在C ++中的代码有什么问题?

Han Qiu

这是代码。

#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; ^

山姆·瓦尔沙夫奇克(Sam Varshavchik)
cout << (p->getTotalNum) << endl;

getTotalNum是一个类方法。因此,必须像其他任何函数一样调用它:

cout << (p->getTotalNum()) << endl;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章