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 the
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.
"Peter Dimov"
From: "Hickman, Greg"
With Borland 5.5.1, I'm not having any luck using a shared_ptr in a boolean context. The compiler complains that the 'if' condition below contains an "Illegal structure operation". Is this a known deficiency with my compiler?
Yes, Borland does have trouble with this construct (i.e. p && q fails), but simple uses such as your program work for me; once again, have you installed the service packs? :-)