Hi there
I was using this code in my program:
And it was working fine.Code:Base *ptr = new Base(para1, para2); v.push_back( ptr );
Then I read how I should check for errors in case the 'new' memory could be gained, so changed my code to this:
But now it fails to compile. Reports :Code:try { Base *ptr = new Base(para1, para2); } catch (bad_alloc& ba) { cerr << "bad_alloc caught: " << ba.what() << endl; } v.push_back( ptr );
I tried removing the curly braces around "Base *ptr = new Base(para1, para2);" but then the compiler(Visual Studio 08 Express) complained that they weren't there. I thought perhaps it was a scope problem.'ptr' : undeclared identifier
Can anyone point out what is wrong with it?
Thanks very much!
EDIT - I did useBTW.#include <new>