VC++6.0下,GDI+对话框工程,从Image派生新类ImageEx,有一个构造函数ImageEx::ImageEx(LPCTSTR sResourceType, LPCTSTR sResource),在对话框类中添加变量:ImageEx* m_image,然后在OnInitDialog()函数中用如下代码:
m_image = new ImageEx("gif","smile");
最后的程序在Release模式下编译、运行无误,但在Debug模式下就会在上面的代码处报告错误:
error C2660: 'new' : function does not take 3 parameters
研究了几天了,实在弄不明白完全一样的代码,在两种模式下会有这样的区别?在Debug下这多出来的第三个参数是什么?请各位帮忙解释一下!谢谢了!!
m_image = new ImageEx("gif","smile");
最后的程序在Release模式下编译、运行无误,但在Debug模式下就会在上面的代码处报告错误:
error C2660: 'new' : function does not take 3 parameters
研究了几天了,实在弄不明白完全一样的代码,在两种模式下会有这样的区别?在Debug下这多出来的第三个参数是什么?请各位帮忙解释一下!谢谢了!!
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif给分吧..哈哈
感谢参与,删去那几行后再编译,涛声依旧^_^
#if defined( _DEBUG )
#undef new
#endif不行的 话,试试
在stdafx.h添加
#define iterator _iterator#ifdef _DEBUGnamespace Gdiplus
{
namespace DllExports
{
#include
};#ifndef _GDIPLUSBASE_H
#define _GDIPLUSBASE_H
class GdiplusBase
{
public:
void (operator delete)(void* in_pVoid)
{
DllExports::GdipFree(in_pVoid);
}void* (operator new)(size_t in_size)
{
return DllExports::GdipAlloc(in_size);
}void (operator delete[])(void* in_pVoid)
{
DllExports::GdipFree(in_pVoid);
}void* (operator new[])(size_t in_size)
{
return DllExports::GdipAlloc(in_size);
}void * (operator new)(size_t nSize, LPCSTR lpszFileName, int nLine)
{
return DllExports::GdipAlloc(nSize);
}void operator delete(void* p, LPCSTR lpszFileName, int nLine)
{
DllExports::GdipFree(p);
}};
#endif // #ifndef _GDIPLUSBASE_H
}
#endif // #ifdef _DEBUG#include
using namespace Gdiplus;
#undef iterator===最后还是不行的话, 参考http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pluslang_new_Operator.asp
ImageEx(IN LPCTSTR sResourceType, IN LPCTSTR sResource);
不知道这个“IN”是什么意思,有没有它们没区别。
class ImageEx : public Image
{
public:
ImageEx(IN LPCTSTR sResourceType,IN LPCTSTR sResource);
ImageEx(const WCHAR* filename, BOOL useEmbeddedColorManagement = FALSE);
~ImageEx();
......};To striking(硬撑者)朋友:
分别加入你给的几段代码后,Rebuild all还是没有用。
#define _GDIPLUSBASE_Hclass GdiplusBase
{
public:
void (operator delete)(void* in_pVoid)
{
DllExports::GdipFree(in_pVoid);
}
void* (operator new)(size_t in_size)
{
return DllExports::GdipAlloc(in_size);
}
void (operator delete[])(void* in_pVoid)
{
DllExports::GdipFree(in_pVoid);
}
void* (operator new[])(size_t in_size)
{
return DllExports::GdipAlloc(in_size);
}
};#endif
-----------------------------------------------------------
的确,new和new[]关键字是被它的基类重载过了,并且只能有一个参数size_t in_size。只是不明白为什么Release下,我的代码又没问题呢?难道这时不管基类中的重载吗?
#define DEBUG_NEW new(THIS_FILE, __LINE__)再加上系统自动生成的下面两行:#ifdef _DEBUG
#define new DEBUG_NEW即Debug下系统调用new的时候果然不是听从基类GdiplusBase中new的,而是Afx.h中那里的new(这时的确有三个参数),按理系统编译到这里应该提示出错在这行:
void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
但它下面这行代码:#define DEBUG_NEW new(THIS_FILE, __LINE__)使得出错行提示又在我的代码中调用new的这行:
m_image = new ImageEx("gif","smile");
让我误会,以为系统把这行当成三个参数了。
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
系统编译时报告的错误是:
gdiplus.lib(imagingguds.obj) : fatal error LNK1103: debugging information corrupt; recompile module
gdiplus.lib(imagingguds.obj) : fatal error LNK1103: debugging information corrupt; recompile module
Linking...
Creating library Debug/xxx.lib and object Debug/xxx.exp
uuid.lib(comcat.obj) : fatal error LNK1103: debugging information corrupt; recompile module
Error executing link.exe.出现环境 xp sp2 + 最新 sdk + vc6 +vc7出现此错误 位 vc6 下编译,问题出来 lib 和 link.exe 版本不合
查看 lib 设置,将 sdk 移动到最后,
编译通过。看来 xp 的 sdk 已经默认的向 vc.net 靠拢了
感谢你对本贴的热心回复,给了我很大的帮助!这个ID没什么分了,这两天才积了一些,我把分加在我以前在基础版开出的一个问题贴中(已经自己解决了),一点心意,请笑纳!!烦请到该贴留个脚印,不胜感激!!http://community.csdn.net/Expert/topic/4550/4550104.xml?temp=.867016