|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-03-26 14:07:14
"Peter Dimov" <pdimov_at_[hidden]> writes:
> Giovanni Bajo wrote:
>> Hello,
>>
>> I have observed a strange behaviour with shared_ptr:
>>
>> struct A
>> {
>> shared_ptr<int> ptr;
>>
>> operator bool()
>> { return ptr; }
>> };
>>
>> A a;
>> a.ptr.reset(new int);
>> assert(a.ptr);
>> assert(a);
>>
>> Now, the second assertion fails (Comeau). It works if for example I
>> change
>> my operator bool into "return ptr ? true : false;". This is
>> counter-intuitive to me. Can anybody explain me why?
>
> Beats me. All other compilers I tried do not assert. On como,
> assert((bool)a.ptr) passes, but even an explicit (bool)ptr inside the
> conversion operator returns false.
Am I crazy, or should there be a pair of parens after "ptr"?
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk