2

I have a C++ project that has been compiling and linking without problems. Recently we added code to override the global new and delete operators and now the project fails to link with the error:

error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined.

I am aware of MS KB148652 and have done what it suggested -- I've placed Nafxcwd.lib and Libcmtd.lib in the Additional Dependencies and Ignore Specific Libary lists. Actually they were already there since I had to add them to eliminate other previous linker errors. I've made sure that the first include in all .cpp files is stdafx.h (as KB148652 suggests) but nothing seems to work.

If anyone can suggest another approach or some direction I haven't tried I'd appreciate knowing about it. Thanks in advance.

4

2 回答 2

1

清理整个项目并尝试从头开始重建它。

于 2010-01-13T15:03:23.307 回答
0

在 c++ 中,重载运算符不是通过类层次结构继承的,因此请尝试在每个派生类中完全重新定义 new 和 delete 的单独副本,而不使用 base_class::operator new 引用基类的定义,
我希望我能帮助你

于 2010-02-23T21:39:55.957 回答