返回信息流我用的是mac上的sublime text编译器写c++。
不知道为什么一直没办法定义类的指针,是定义方法有问题么?
一直显示reference to non-static member function must be called
比如这样的
#include <iostream>
using namespace std;
class father
{
public:
father(){cout<<"构造father"<<endl;}
~father(){cout<<"析构father"<<endl;}
virtual void cool(){cout<<"father is cool"<<endl;}
};
class son:public father
{
public:
son(){cout<<"create son"<<endl;}
~son(){cout<<"delete son"<<endl;}
void cool(){cout<<"son is cool"<<endl;}
};
int main()
{
father *p=new son;
p->cool;
return 0;
}
试了几种方法都不行。
这是一条镜像帖。来源:北邮人论坛 / cpp / #88583同步于 2015/9/11
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
新手求指教
CcZhome
2015/9/11镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
【 在 CcZhome 的大作中提到: 】
: 我用的是mac上的sublime text编译器写c++。
: 不知道为什么一直没办法定义类的指针,是定义方法有问题么?
: 一直显示reference to non-static member function must be called
: ...................
1. Sublime是个编辑器。
2. reference to non-static member function must be called.
3. 如果书上就是这么写的,换一本教材吧。比如换成《C++ Primer》第五版。
4. 在Mac里装一个VMware来跑 Visual Studio 2013 + Resharper C++ 挺好的。
加了括号在我的电脑上就可以跑了,其他不知道
用的vs
【 在 CcZhome 的大作中提到: 】
:
: 有没有括号不影响对象的定义吧
: 来自「北邮人论坛手机版」
同楼上,也用VS编译了一下。
error C3867: “father::cool”: 函数调用缺少参数列表;请使用“&father::cool”创建指向成员的指针
cool不加括号被认为是father的成员。加了括号正常。