Boost logo

Boost Users :

From: Edward Diener (eddielee_at_[hidden])
Date: 2003-04-23 19:47:43


dick.bridges_at_[hidden] wrote:
> What is the 'correct' way to return a NULL/empty shared_ptr? For
> example, this works
>
> <snippet>
> shared_ptr<int> maybe_get_a_pointer()
> {
> shared_ptr<int> p;
> return(p);
> }
> </snippet>
>
> but seems 'klunky'. I've clearly missed something in the
> docs/examples somewhere. Can someone point me in the right direction?

What is klunky about it ? It seems pretty normal to me. Another other
possibility is to passed a reference to a shared_ptr<> and have your
function above fill it in with an actual pointer to int and return a bool
true if it succeeded or false if it did not. Another possibility is to use
boost::optional<>. Another one to pass back a bool,shared_ptr<> std::pair or
boost::tuple. But I prefer the method you used originally.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net