我在 new 的调试版本上使用 __declspec(dllimport/export):
#ifdef _DEBUG
DECLSPECCORE extern void* operator new(unsigned int size, const char* file, int line);
extern void* operator new[](unsigned int size, const char* file, int line);
extern void operator delete(void* address, const char* file, int line);
extern void operator delete[](void* address, const char* file, int line);
extern void Delete(void* address);
#define LUDO_NEW new(__FILE__, __LINE__)
#define LUDO_DELETE delete
#endif
这让我得到了
error C2375: 'operator new': redefinition; different linkage.
这是为什么?如何解决?这是我目前正在编译的唯一项目。
最佳答案
C++ 运行时本身提供了一个 operator new
,它没有被标记为 DECLSPECCORE
—— 因此是“不同的链接”,原始的不是从另一个模块导入的。如果您打算覆盖 operator new
,它应该具有与以前相同的链接。
关于c++ - 'operator new' : redefinition, 不同的链接(在重新定义的新运算符上使用 _dllspec),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1567972/