In C++, I'm trying to define a type suitable for a pointer to one of several member functions of my class cBar
(all functions have the same interface, say accept an int
and return void
).
For now, I'm making a global type tHandler
suitable for a pointer to one of several global functions accepting an additional parameter me
, holding a pointer to my class cBar
, as follows:
typedef void(*tHandler)(class cBar *const me, int val);
void Handler0(class cBar *const me, int val);
void Handler1(class cBar *const me, int val);
class cBar {
tHandler fCurrentHandler;
/*..*/
public:
inline void cBar::CurrentHandler(int val) {
(*fCurrentHandler)(this,val);
}
inline cBar() {
fCurrentHandler = Handler0;
CurrentHandler(0);
}
inline ~cBar() {
CurrentHandler(-1);
}
};
This is ugly; in particular Handler0
and Handler1
should be private methods of cBar
, and tHandler
should be a private type.
Any clue? TIA.