1 CTestDlg *x;
2 x=new CTestDlg(this);
3 Graphics *y;
4 y=new Graphics(m_hWnd);是不是几乎一模一样的东西,VC6.0却说:error C2660: 'new' : function does not take 3 parameters 指的是第 4 行!为啥第2行没问题第四行却出毛了呢??我知道去掉
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
就没事了 可是我想知道为什么 2跟4一样的东西不可能有代码歧视吧。
2 x=new CTestDlg(this);
3 Graphics *y;
4 y=new Graphics(m_hWnd);是不是几乎一模一样的东西,VC6.0却说:error C2660: 'new' : function does not take 3 parameters 指的是第 4 行!为啥第2行没问题第四行却出毛了呢??我知道去掉
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
就没事了 可是我想知道为什么 2跟4一样的东西不可能有代码歧视吧。
解决方案 »
- EDIT背景色问题
- 请教VC如何将XML文件插入到数据库中?
- 老牌vc群招人,765418 要求爱回答问题,爱问问题,本群定期清理 本群2群 9978616欢迎加入 up有分
- 急急急 有哪位大侠知道,数据库格式转换 (高分)
- 在回调函数中怎么得到对话框的句柄?
- 有关注册表DWORD 的读写问题(很急阿)
- 文件保存问题
- 在取得一个对话框的句柄之后,怎样分别取到对话框上各控件的句柄?
- VC中CString参数传到fastReport模板的问题?
- 哪里有msdn中的有关isapi的例子?大虾帮忙!!!!!!!!!!52分全送了!!!!!
- 关于函数的返回值是数组
- MFC 语法错误 : 缺少“;”(在标识符“m_sSplitFlag”的前面)
但是书里写Pen pen(Color.Blue);我却编译不过 只有换成Pen pen(Color::Blue);才可以 为什么呢
问题现象When you build a debug version of a Microsoft Foundation Classes (MFC) application that uses GDI+, you may receive an error message that resembles the following:
error C2660: ‘Gdiplus::GdiplusBase::operator new’ : function does not take 3 parameters在我们使用GDI+的时候,如果程序是一个MFC程序,并且是在debug模式下,那我们可能会得到如下的错误信息:
error C2660: ‘Gdiplus::GdiplusBase::operator new’ : function does not take 3 parametersCAUSE
原因In debug builds, MFC defines a preprocessor macro that expands the new operator to an overloaded new operator that takes two extra parameters. The extra parameters are the source file name and code line number. MFC can use this information to report memory leaks to the programmer when in debug mode. This works for MFC classes because MFC provides overloads for new that accept the extra parameters.However, because this expansion is done by the preprocessor, it affects all usage of the new operator. If any non-MFC classes are used in the project, their new operator is also expanded, even if no suitable overload of new is available in that class. This is what happens in GDI+, and as a result, you receive a compile-time error message.
在debug模式下,MFC程序要使用一个宏定义来扩展new操作符,使之需要接受两个附加的参数。这两个附加参数分别是源程序的文件名和代码行号。MFC使用它们在debug模式下向程序员报告内存泄漏的信息。MFC类由于重载了new操作符,所以可以正常的与扩展后的new操作符搭配使用。但是,非MFC类则无法与这种扩展的new操作符正常工作。GDI+就属于这种情况。AFX.h中有这样两段,楼主自己对比一下吧,我也搞不太懂了:
// Memory tracking allocation
void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
#define DEBUG_NEW new(THIS_FILE, __LINE__)
#if _MSC_VER >= 1200
void AFX_CDECL operator delete(void* p, LPCSTR lpszFileName, int nLine);
#endif
有可能void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);就是MFC重载的new操作符#if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
// for file name/line number tracking using DEBUG_NEW
void* PASCAL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
#if _MSC_VER >= 1200
void PASCAL operator delete(void *p, LPCSTR lpszFileName, int nLine);
#endif
#endif