16 Dec
2002
16 Dec
'02
3:42 p.m.
On Monday 16 December 2002 07:05 am, Steven Green wrote:
if (b)
-- Darin
Personally, I use if ( b.get() ), because on at least one compiler (Sun Workshop 5), the simpler syntax caused a compiler error.
I prefer to use if(!!b) because then it will still work if you change the pointer type later on in the project and only requires an operator!() instead of the more dangerous operator bool (compiler can do automatic type conversions behind your back leading to possible bugs if you are not careful).
- Steven Green http://www.greenius.ltd.uk
FWIW, shared_ptr doesn't actually have an operator bool. It uses the safe_bool idiom (as do other Boost libraries) to eliminate most automatic type conversions. Doug