I do not think that you are allowed to compare 0(or NULL) with pointers to member functions, especially since they may not be pointers (for example, if a function virtual).
Personally, I rewrote the test ifwithout comparison, for example:
void DoStuff() {
if (m_callback) {
(m_object->*m_callback)();
} else {
m_object->DoNormalCallback();
}
}
And, for bonus points, run this int test in the constructor.
class MyClass {
SomeOtherClass * m_object;
void (SomeOtherClass::*m_callback)();
public:
MyClass(SomeOtherClass * _object,void (SomeOtherClass::*_callback)()=NULL) :
m_object(_object),m_callback(_callback)
{
if (!m_callback) {
m_callback = &SomeOtherClass::DoNormalCallback;
}
}
void DoStuff() {
(m_object->*m_callback)();
}
};
source
share