坑爹的奇怪的new 坑爹的奇怪的GDI+
1CTestDlg *x;
2x=new CTestDlg(this);
3Graphics *y;
4y=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一样的东西不可能有代码歧视吧。。。。
[解决办法]
转过来的:
- C/C++ code
问题现象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+就属于这种情况。