Re: AutoPtr::operator == : Is it defined the correct way ??
- From: "Gabest" <gabest@xxxxxxxxxxx>
- Date: Wed, 22 Mar 2006 14:44:48 +0100
Not Exactly. How about the comparision operator over strings (which are
nothing but wrappers around char* pointers) ? Do we compare the internal
char* pointers or their content?
Well, no. Strings are strings, pointers are pointers, value types are value
types. Regardless their wrapper object. That's how I think about them and
the needed operation of comparing.
Or what would you suggest for a CComPtr<...>::operator == (const
CComPtr<...>& ptr) to do? CAutoPtr is basically CComPtr with only one
reference allowed at the same time. They could have been implemented as one
single class even, with some const int template argument for the refcount.
Would you not implement a value equality check (say we have a common
ICompare interface what every comparable object implements) just because it
allows multiple references to the same pointer, and in this case it is
meaningful to do the comparision of the addresses? I think what you are
suggesting is use the otherwise meaningless operator == to something else
because it comes handy in some way.
MyClass::UnSubscribe(CAutoPtr<IEventFunctor>& spFunc)
{
POSITION pos = m_List.Find(spFunc);
if(pos)
m_List.RemoveAt(pos);
}
There is nothing wrong with the above code semantically - but it simply
I think there is!
Let's say you cannot afford the luxury to use CAutoPtr and have to use good
old pointers and m_List is just a CAtlList<IEventFunctor*>.
MyClass::UnSubscribe(IEventFunctor* spFunc)
{
POSITION pos = m_List.Find(spFunc);
if(pos)
{
delete m_List.GetAt(pos);
m_List.RemoveAt(pos);
}
}
Will this code work? No. For the same reason.
To my opinion such rewrite of any code which uses CAutoPtr must be possible
vica-versa. Redefining operator == destroys this symmetry between pointers
and auto pointers.
if CAutoPtr never defined its operator==. Becuase, that would force the
developers not to use Find() on the CAutoPtrList. Being unaware, I used
it -
Maybe CAutoPtrList shouldn't have an public Find function in the first place
:)
and the system went wrong, and it took to me somewhile to realize what is
going on.
Sure because you thought it compares the value, but this would have never
occured to me and I might got tricked by the opposite if it was working like
that.
.
- Follow-Ups:
- Re: AutoPtr::operator == : Is it defined the correct way ??
- From: P.GopalaKrishna
- Re: AutoPtr::operator == : Is it defined the correct way ??
- References:
- Re: AutoPtr::operator == : Is it defined the correct way ??
- From: Gabest
- Re: AutoPtr::operator == : Is it defined the correct way ??
- From: P.GopalaKrishna
- Re: AutoPtr::operator == : Is it defined the correct way ??
- Prev by Date: Re: Advise fails, while DLL try to call COM EXE
- Next by Date: Re: IConnectionPointContainer ptr does not release !!
- Previous by thread: Re: AutoPtr::operator == : Is it defined the correct way ??
- Next by thread: Re: AutoPtr::operator == : Is it defined the correct way ??
- Index(es):
Relevant Pages
|