干了这么多年c/c++,这个问题都不能解决。汗颜,大家出手.
xisha 2002-11-20 03:50:08 要重载全局的new ,delete.
我在老工程里加了几行
inline void* __cdecl operator new(unsigned int s)
{
return (void*)1;
}
在Embedded vc++环境下编译报错:
uafxwced.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in mmmDlg.obj
新开了个MFC APP工程,加入上面的几行代码,能编译和正常运行;
为何老工程加入上面的几行代码链接c出错,
在PC 的VC60下加入上面的几行代码出错更奇怪:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void* operator new(unsigned int s)
{
return (void*)1;
}
/////////////////////////////////////////////////////////////////////////////
// CPppDlg dialog
CPppDlg::CPppDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPppDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPppDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
编译报错:
D:\vc\ppp\pppDlg.cpp(14) : error C2061: syntax error : identifier 'THIS_FILE'
D:\vc\ppp\pppDlg.cpp(15) : error C2091: function returns function
D:\vc\ppp\pppDlg.cpp(15) : error C2809: 'operator new' has no formal parameters