超有挑战性的 error C2661: “operator new”

dothome 2010-02-06 10:22:34
该工程的release版本编译通过可正确运行;但是debug版本编译出现如下问题(编译器vs2003):

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xmemory(34) : error C2661: “operator new” : 没有重载函数接受 3 个参数
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xmemory(137) : 参见对正在编译的函数模板实例化“_Ty *std::_Allocate::value_type>(size_t,_Ty *)”的引用
with
[
_Ty=std::allocator::value_type
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xmemory(136) : 编译类模板成员函数“std::allocator<_Ty>::pointer std::allocator<_Ty>::allocate(std::allocator<_Ty>::size_type)”时
with
[
_Ty=char
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xstring(30) : 参见对正在编译的类模板实例化“std::allocator<_Ty>”的引用
with
[
_Ty=char
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xstring(46) : 参见对正在编译的类模板实例化“std::_String_val<_Ty,_Alloc>”的引用
with
[
_Ty=char,
_Alloc=std::allocator
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\stdexcept(39) : 参见对正在编译的类模板实例化“std::basic_string<_Elem,_Traits,_Ax>”的引用
with
[
_Elem=char,
_Traits=std::char_traits,
_Ax=std::allocator
]

难度在于无法定位错误在工程的源文件中的位置,双击后跳转到库文件中。
各位有什么办法吗?
...全文
877 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
dothome 2010-02-08
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 loaden 的回复:]
找找stdafx.h吧,里面定义了一个宏:
#define DEBUG_NEW new
把STL相关的头文件放在这个宏的前面!
[/Quote]

没有定义这个宏,用了MFC的自动生成框架才会有这个宏吧?我没有用MFC
dothome 2010-02-08
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 baihacker 的回复:]
在适当的位置加上#include <new>
呢?
[/Quote]

在stdafx.h中加了,也无效
dothome 2010-02-08
  • 打赏
  • 举报
回复
确实是包含了一个文件,其中用到了DEBUG_NEW
结贴,感谢飞雪与老邓以及其它朋友
dothome 2010-02-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yshuise 的回复:]
贴源码吧
[/Quote]

难度就在于这个错误无法在源码中定位,不知由何处引起。而文件有近200个之多。
非不愿帖,实不能也
dothome 2010-02-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 proteas 的回复:]
你把头文件包含到 #DEFINE new 的后面了。
放到前面就可以了。
[/Quote]

工程中没有搜到“#DEFINE new ”
某某9 2010-02-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 proteas 的回复:]
你把头文件包含到 #DEFINE new 的后面了。
放到前面就可以了。
[/Quote]????
Proteas 2010-02-06
  • 打赏
  • 举报
回复
你把头文件包含到 #DEFINE new 的后面了。
放到前面就可以了。
xylicon 2010-02-06
  • 打赏
  • 举报
回复
没源码,没真相。
yshuise 2010-02-06
  • 打赏
  • 举报
回复
贴源码吧
老邓 2010-02-06
  • 打赏
  • 举报
回复
找找stdafx.h吧,里面定义了一个宏:
#define DEBUG_NEW new
把STL相关的头文件放在这个宏的前面!
traceless 2010-02-06
  • 打赏
  • 举报
回复
飞雪一如既往 的耐心

up 飞雪
baihacker 2010-02-06
  • 打赏
  • 举报
回复
有四个形式的:
void* operator new(std::size_t) throw(std::bad_alloc);
void* operator new[](std::size_t) throw(std::bad_alloc);
void operator delete(void*) throw();
void operator delete[](void*) throw();
可以直接去replace
而总共有:
void* operator new(std::size_t size) throw(std::bad_alloc);
void* operator new(std::size_t size, const std::nothrow_t&) throw();
void operator delete(void* ptr) throw();
void operator delete(void* ptr, const std::nothrow_t&) throw();
void* operator new[](std::size_t size) throw(std::bad_alloc);
void* operator new[](std::size_t size, const std::nothrow_t&) throw();
void operator delete[](void* ptr) throw();
void operator delete[](void* ptr, const std::nothrow_t&) throw();
void* operator new (std::size_t size, void* ptr) throw();
void* operator new[](std::size_t size, void* ptr) throw();
void operator delete (void* ptr, void*) throw();
void operator delete[](void* ptr, void*) throw();
其它形式的需要加上#include <new>
否则就是ill-formed的。


这里还有一个可能的原因就是DEBUG_NEW。
baihacker 2010-02-06
  • 打赏
  • 举报
回复
在适当的位置加上#include <new>
呢?

64,701

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧