On Oct 7, 10:21 am, "A.Gallus" <u...@rz.uni-karlsruhe.dewrote:
I want to define a functor which calls methods of other classes via a
function pointer:
class play
{
public:
void operator ()
{
(*this.*fp)();
}
private:
void (OtherClass::*fp) ();
};
Is this possible somehow?
Of course. You're on the right track, the only thing is in the
operator()():
1. You need an object of type OtherClass (or a pointer to such
an object); you can't use a pointer to a member of
OtherClass with this (which is a pointer to play).
2. Your syntax isn't quite right for the call. If you have a
pointer, then it would be (otherObject->*fp)() if you have
a reference or an object, (otherObject.*fp)().
3. And also, it should be operator()().
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34