Login  Register

Re: Bug in Handle::operator==?

Posted by Luigi Ballabio-2 on Jul 06, 2004; 7:59am
URL: http://quantlib.414.s1.nabble.com/Bug-in-Handle-operator-tp3035p3038.html

On 2004.06.16 14:23, [hidden email] wrote:

> What now comes is may be a bug report:
>
> The operator== of a Handle is for example used by
> Observer::unregisterWith(), where the observer has to find the
> observable with which it wants to unregister.
> I looked at the code and found:
>
> template <CLASS T>
> inline bool Handle<T>::operator==(const Handle<T>& h) const {
>   return (n_ == h.n_);
> }
>
> As I understand, h.n_ is the reference count, not the pointer to the
> object.

Hi,
        the above is correct: h.n_ is a pointer to the integer holding  
the reference count, not its value. Testing for equality of such  
pointer is actually stricter than testing for equality of the pointers  
to the object: in the first case, two handles are deemed equal only if  
one of them is a copy of the other, while in the second case, all null  
handles, however instantiated, would be considered equal.

Later,
        Luigi