开发者

MFC: new object - error message?

开发者 https://www.devze.com 2023-04-12 23:12 出处:网络
I have a class (Event.h): class CEvent { publi开发者_高级运维c: CEvent(); ~CEvent(); int nVal; }; defined in Event.cpp

I have a class (Event.h):

class CEvent 
{
   publi开发者_高级运维c:
   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..


CEvent is also the name of a class in MFC. I would rename the class to prevent confusion.


Found the problem:

#ifdef _DEBUG
#define DEBUG_NEW
#endif

was included in a different class. This was impacting 'new' everywhere! Commenting this out clears the error.

Go figure.

0

精彩评论

暂无评论...
验证码 换一张
取 消