Filip Konvička | 15 Jul 16:17
Picon

Re: how can I return a 'null' smart pointer?

>> What is so bad in general about returning uninitialized smart pointers?
>> Is that more costly than throwing an exception? I mean, there is even
>> some support for testing a smart pointer for validity built into
>> shared_ptr, so why not use it where appropriate?
>>
> 
> The only problem with returning a null pointer, or -1,
> or whatever in case of error is that it's easy to ignore
> at the calling scope, so the upper layers would not even know
> the error occurred. Exception, on the other hand, propagates
> up the stack enforcing more structured error handling.

I agree, but only if the case is an error. In my application, I have 
several places where the "null" value is a regular result. That's what I 
meant by saying "where appropriate".

Cheers,
Filip

Gmane