[英]new operator with CArray results in an error
I have the following MFC (C++) code that allocates a pointer to an array without the need to raise exceptions in case of low memory condition. 我有以下MFC(C ++)代码,该代码将指针分配给数组,而在内存不足的情况下无需引发异常。 I compile it with Visual Studio 2008. 我用Visual Studio 2008编译它。
struct MY_ITEM_INFO
{
CString str;
int n;
MY_ITEM_INFO()
{
n = 0;
}
};
CArray<MY_ITEM_INFO>* pArrResItems = new (std::nothrow) CArray<MY_ITEM_INFO>();
if(pArrResItems != NULL)
{
//Got it!
//Remove it
delete pArrResItems;
}
Which gives me the following error message on a new
operator line when I try to compile it: 当我尝试对其进行编译时,这会在new
运算符行上给出以下错误消息:
error C2665: 'CObject::operator new' : none of the 3 overloads could convert all the argument types
could be 'void *CObject::operator new(size_t,void *)'
Any idea how to make it to compile? 任何想法如何使其编译?
OK. 好。 I got it, the new
line should've been this (or take new
operator from the global namespace): 我知道了, new
行应该是这个(或者从全局名称空间中获取new
运算符):
CArray<MY_ITEM_INFO>* pArrResItems = ::new (std::nothrow) CArray<MY_ITEM_INFO>();
Evidently the new
operator for CObject does not support nothrow_t
. 显然,CObject的new
运算符不支持nothrow_t
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.