我有以下 MFC (C++) 代码,它分配一个指向数组的指针,而无需在内存不足的情况下引发异常。我用 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;
}
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 *)'
知道如何编译吗?