Auto ptr initialization

Is a null check needed for the pointer aPtrDevFile (like we usually do after every new function call), after initializing an auto pointer as below:

<code>
std::auto_ptr<DevFile> aPtrDevFile (new DevFile);
</code>

Thanks!
new does not return null when it fails, it throws an exception.
Thanks for the correction.

The question still remains unanswered.
No, it doesn't. If new can never return null, why would you need to check the return value for null?
Well what I mean is, if new throws exception, we still need to have a try-catch block around that auto-ptr initialization, right?
If for some reason you want to handle the case that there is not enough memory for that specific allocation, then yes. Otherwise, no.

Or to put it differently: if you have a backup plan in case the allocation fails, catch the exception. If not, then let it be caught by someone who does have a backup plan somewhere higher up the chain. When there is none, let the program terminate.
Last edited on
Topic archived. No new replies allowed.