No, obj cannot be NULL .
If new fails, it throws a std::bad_alloc . If no exception has been thrown, obj guaranteed to point to a fully initialized instance of Object .
There is a new option that does not throw an exception
Object *obj = new(nothrow) Object();
In this case, obj will be NULL if new fails and the std::bad_alloc not std::bad_alloc (although the Object constructor can obviously still throw exceptions).
In some older compilers, new cannot throw an exception and return NULL instead, but this does not conform to the standard of behavior.
If you overloaded operator new , this may behave differently depending on your implementation.
Sven
source share