MFC:新对象 - 错误消息?
我有一个类(Event.h):
class CEvent
{
public:
CEvent();
~CEvent();
int nVal;
};
在 Event.cpp 中定义
#include "event.h"
CEvent::CEvent() {}
CEvent::~CEvent() {}
在另一个类中,我包含了“event.h”并正在尝试以下操作:
CEvent* pEvent = new CEvent();
但是我收到编译器错误:
error C2440: 'initializing' : cannot convert from 'CEvent' to 'CEvent *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
我做错了什么?这确实是一件微不足道的事情,我离得太近而看不到它。
使用 VC 2008..fwiw..
I have a class (Event.h):
class CEvent
{
public:
CEvent();
~CEvent();
int nVal;
};
defined in Event.cpp
#include "event.h"
CEvent::CEvent() {}
CEvent::~CEvent() {}
In a different class I have included "event.h" and am trying the following:
CEvent* pEvent = new CEvent();
But Im getting a compiler error:
error C2440: 'initializing' : cannot convert from 'CEvent' to 'CEvent *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
What am I doing wrong? This is something truly trivial and Im too close to see it.
Using VC 2008.. fwiw..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CEvent也是MFC中的一个类的名称。
我会重命名该类以防止混淆。
CEvent is also the name of a class in MFC.
I would rename the class to prevent confusion.
发现问题:
被分在不同的班级。这对各地的“新”产生了影响!将此注释掉可以清除错误。
去算算吧。
Found the problem:
was included in a different class. This was impacting 'new' everywhere! Commenting this out clears the error.
Go figure.