2

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)
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
acwatson421
  • 47
  • 1
  • 6

1 Answers1

9

bad_alloc is defined in the header new.

#include <new>

In namespace std.

using namespace std
Arjen
  • 636
  • 1
  • 7
  • 13
  • 1
    This ended up working perfectly, so thank you to arjenz and stellarossa. However, I'm curious as to why it would have caused a problem in this class but not in the other. Obviously its hard to answer a question like that without looking at the other code, but I didn't have any standard libraries included in the other class, nor did I use namespace std. – acwatson421 Nov 07 '13 at 01:50