
dick.bridges@tais.com 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.