I’m trying to overload the == operator to compare between two objects. For some reason the overloaded handler is never called.
class gxCallback
{
public:
virtual bool operator==(const gxCallback &aOther) const
{
// This is never called
return true;
}
};
typedef std::vector < gxCallback* > CallbackList;
void gxObservable::Fire( gxCallback *aCallback )
{
CallbackList::iterator iCallback;
for ( iCallback = mCallbacks.begin(); iCallback != mCallbacks.end(); ++iCallback )
{
if ( aCallback == *iCallback ) // The comparison is never made via the overloaded ==
{
// Do something
}
}
}
You’re calling it on a pointer, not the object. You’ll have to compare the object with the one the iterator is referencing:
You also have to make sure the “pointers” hold something before you dereference them.