What do you mean by "instance"?
In a standard compatible implementation, either MyClass was built, or an exception was thrown, and auto_ptr would no longer be in scope. So, in the above example, the value of the pointer represented by your auto_ptr cannot be NULL .
(Perhaps you are using support without exception support, which can return NULL if the selection (nothrow) exception), even without using the (nothrow) , but this is not a common case.)
Generally speaking, you can check the value of a pointer. You just need to get a basic view, because as you discovered, std::auto_ptr does not have operator== .
To do this, use X* std::auto_ptr<X>::get() const throw() , for example:
if (myPointer.get()) { // ... }
Also note that std::auto_ptr deprecated in C ++ 0x, in favor of std::unique_ptr . Prefer the latter when you have access to the appropriate implementation.
Lightness races in orbit
source share