classes & function pointers

Started by
0 comments, last by Themis 21 years, 3 months ago
Hello, I want to ask about pointers to functions in C++. When I want to use a function pointer in C I use a simple typedef like the following: typedef int (*pFunc)(void *); and then I give as an argument the name of a proper function in another one. My problem is that if the function whose pointer I want to give is an object''s method then the compiler starts complaining. eg. void foo(int x, pFunc func); class cClass { int myFunc(void *x); }; int main() { cClass myClass; int x=0; foo(x, myClass.myFunc); //compiler complaints return 0; } -------------------------------------------------------------------------------- How can I overcome this problem? I ''ve tried to typecast the method eg foo(x, (pFunc)myClass.myFunc); but this as you might know doesn''t work . Can you help me with this? Thanks, Themis
Advertisement
your best source for information on this is http://www.function-pointer.org/
to make it short:


  typedef void ( myclass::*FUNC ) ( int );myclass obj;				// instantiate myclassFUNC f = obj.myfunc;			// assign adress( obj.*f ) ( 123 );			// and call it  



Runicsoft -- latest attraction: obfuscated Brainfuck Interpreter in SML

This post was made entirely from re-cycled electrons

This topic is closed to new replies.

Advertisement