25 Sep
2002
25 Sep
'02
4:49 p.m.
I've written my own smart pointer classes but have mostly switched over to Boost. What I've wondered is why the Boost smart pointers use various methods to achieve this boolean conversion instead of a single method of
From: "Alan M. Carroll, CodeSlinger"
form
operator void const * () const { return px; }
This enables the standard boolean uses ("if (ptr)", "if (!ptr)") and also allows direct comparison between a raw pointer and the shared pointer. It also doesn't seem to allow bad leakage of the pointer because a (void const*) can only be used for comparison. I've looked through the news groups and Boost documentation and seen no mention of this.
delete ptr; // ;-) In the general case unwanted comparisons are a problem, too.