문제

I'm getting a compiler error:

error C2061: syntax error : identifier 'bad_alloc'

I've used the chunk of code below in other projects before, with different memory allocation within the try block, without problems. I was hoping someone could explain to me why bad_alloc isn't being recognized by VS10 despite it not causing the same problem in use in other programs? Odds are I missed some minor syntactical thing, but I've spent hours trying to figure it out, and at this point I feel like I'm probably blind to the error. Thanks for the help!

try
{
    node* tbr = new node();
    return tbr;
} // End try allocation

catch(bad_alloc)
{
     throw OutOfMemoryException();
} // End catch(bad_alloc)
도움이 되었습니까?

해결책

bad_alloc is defined in the header new.

#include <new>

In namespace std.

using namespace std
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top