无法识别bad_alloc标识符

bad_alloc identifier not recognized?

本文关键字:alloc 标识符 bad 识别      更新时间:2023-10-16

我收到编译器错误:

错误

C2061:语法错误:标识符"bad_alloc"

我之前在其他项目中使用过下面的代码块,在 try 块中分配不同的内存,没有问题。我希望有人能向我解释为什么VS10没有识别bad_alloc尽管它不会在其他程序中引起相同的问题?很有可能我错过了一些小的语法问题,但我花了几个小时试图弄清楚它,在这一点上,我觉得我可能对错误视而不见。感谢您的帮助!

try
{
    node* tbr = new node();
    return tbr;
} // End try allocation
catch(bad_alloc)
{
     throw OutOfMemoryException();
} // End catch(bad_alloc)
bad_alloc在

标头new中定义。

#include <new>

在命名空间标准中。

using namespace std