我遇到编译器错误:
错误 C2061:语法错误:标识符“bad_alloc”
我以前在其他项目中使用过下面的代码块,在 try block 中使用不同的内存分配,没有问题。我希望有人能向我解释为什么 bad_alloc 没有被 VS10 识别,尽管它在其他程序中使用时不会导致同样的问题?很可能我错过了一些小的句法问题,但我花了几个小时试图弄清楚,在这一点上,我觉得我可能对错误视而不见。感谢您的帮助!
try
{
node* tbr = new node();
return tbr;
} // End try allocation
catch(bad_alloc)
{
throw OutOfMemoryException();
} // End catch(bad_alloc)
最佳答案
bad_alloc 在头文件 new 中定义。
#include <new>
在命名空间 std 中。
using namespace std
关于c++ - bad_alloc 标识符无法识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19821495/