F
Francois Grieu
Hello,
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 type tHandler suitable for a pointer
to a global function accepting an additional parameter "me",
holding a pointer to my class:
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 works, but is ugly; in particular Handler0/Handler1 should
be private methods of cBar, and tHandler a private type.
Any idea ?
TIA,
Francois Grieu
Note: this is not homework, I'm moving to C++ from an embedded C
background.
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 type tHandler suitable for a pointer
to a global function accepting an additional parameter "me",
holding a pointer to my class:
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 works, but is ugly; in particular Handler0/Handler1 should
be private methods of cBar, and tHandler a private type.
Any idea ?
TIA,
Francois Grieu
Note: this is not homework, I'm moving to C++ from an embedded C
background.