std::bad_alloc的编译错误

g_yxh 2008-03-04 01:40:25
vs2005下编译,有下面的问题:

c:\program files\microsoft visual studio 8\vc\include\xdebug(83) : error C2440: '<function-style-cast>' : cannot convert from 'void *' to 'std::bad_alloc'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1> c:\program files\microsoft visual studio 8\vc\include\xdebug(79) : while compiling class template member function 'char *std::_DebugHeapAllocator<_Ty>::allocate(std::allocator<_Ty>::size_type,const void *)'
1> with
1> [
1> _Ty=char
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\xdebug(106) : see reference to class template instantiation 'std::_DebugHeapAllocator<_Ty>' being compiled
1> with
1> [
1> _Ty=char
1> ]

但这个xdebug是系统的文件啊,是什么错误呢?
...全文
217 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
g_yxh 2008-03-04
  • 打赏
  • 举报
回复
刚才偶然找到解决的方法了, 我把#include <string.h> 和#include自己的一个头文件交换了顺序,编译就通过,但还没找到具体是什么原因,下来我再慢慢看了:)
代码太多,不确定是哪里导致的错,所以没法贴了
总之谢谢!
真相重于对错 2008-03-04
  • 打赏
  • 举报
回复
你的代码造成它出错,
贴出你的代码?
g_yxh 2008-03-04
  • 打赏
  • 举报
回复
出错的是vc自带的代码:xdebug
template<class _Ty>
class _DebugHeapAllocator
: public allocator<_Ty>
{ // an allocator which uses the debug CRT heap
public:

template<class _Other>
struct rebind
{ // convert _DebugHeapAllocator<_Ty> to _DebugHeapAllocator<_Other>
typedef typename _DebugHeapAllocator<_Other> other;
};

typename allocator<_Ty>::pointer __CLRCALL_OR_CDECL allocate(typename allocator<_Ty>::size_type _Count, const void *)
{ // check for integer overflow
if (_Count <= 0)
_Count = 0;
else if (((size_t)(-1) / _Count) < sizeof(_Ty))
_THROW_NCEE(std::bad_alloc, NULL);

// allocate array of _Count elements, ignore hint
return ((_Ty *)_NEW_CRT char[_Count * sizeof(_Ty)]);
}

typename allocator<_Ty>::pointer __CLR_OR_THIS_CALL allocate(typename allocator<_Ty>::size_type _Count)
{ // check for integer overflow
if (_Count <= 0)
_Count = 0;
else if (((size_t)(-1) / _Count) < sizeof(_Ty))
_THROW_NCEE(std::bad_alloc, NULL);

// allocate array of _Count elements
return ((_Ty *)_NEW_CRT char[_Count * sizeof(_Ty)]);
}

void __CLR_OR_THIS_CALL deallocate(typename allocator<_Ty>::pointer _Ptr, typename allocator<_Ty>::size_type)
{ // deallocate object at _Ptr, ignore size
_DELETE_CRT_VEC(_Ptr);
}
};
kkun_3yue3 2008-03-04
  • 打赏
  • 举报
回复
把代码贴出来

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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