Click here to Skip to main content
15,912,977 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Function Pointer Pin
Stuart Dootson2-Mar-09 8:02
professionalStuart Dootson2-Mar-09 8:02 
GeneralRe: Function Pointer Pin
dehseth2-Mar-09 8:14
dehseth2-Mar-09 8:14 
GeneralRe: Function Pointer Pin
Stuart Dootson2-Mar-09 8:17
professionalStuart Dootson2-Mar-09 8:17 
QuestionRe: Function Pointer Pin
CPallini2-Mar-09 10:17
mveCPallini2-Mar-09 10:17 
GeneralRe: Function Pointer Pin
Richard Andrew x642-Mar-09 9:38
professionalRichard Andrew x642-Mar-09 9:38 
GeneralRe: Function Pointer [modified] Pin
Stuart Dootson2-Mar-09 10:02
professionalStuart Dootson2-Mar-09 10:02 
GeneralRe: Function Pointer Pin
Rajesh R Subramanian2-Mar-09 19:59
professionalRajesh R Subramanian2-Mar-09 19:59 
AnswerRe: Function Pointer Pin
Perisic, Aleksandar2-Mar-09 8:45
Perisic, Aleksandar2-Mar-09 8:45 
There are three reasons you can't do this the way you think it should work:

First &a.run is not the right way of getting a pointer to a class function, it is &A::run.
Second you can't convert from your Method type above to &A::run.
Third you can't execute a non-static method of a class unless you have an instance of that class (and this looks quite normal because we have to know which instance it is whose method we want to execute, non-static method have no meaning without an instance)

This is how you would write it using your way of thinking:
class A{
	public:	void run(void);
};

class R{
public:	

	typedef void (A::*Method)();
	Method onClick;	

	void Do(A* a)	
	{		
		(a->*onClick) ();	
	}
};

int _tmain(int argc, _TCHAR* argv[])
{	
	printf("main\n");		
	A a;	
	R r;	
	r.onClick = &A::run;
	r.Do(&a);...
}


As you can see however there is nothing much useful to generalize, so the above code is just hiding something for no apparent reason. But you needed an answer Smile | :)

You can't create a pointer for one class non-static method and use it as a pointer to another class method.
GeneralRe: Function Pointer Pin
Perisic, Aleksandar2-Mar-09 9:08
Perisic, Aleksandar2-Mar-09 9:08 
AnswerRe: Function Pointer [modified] Pin
Perisic, Aleksandar2-Mar-09 11:48
Perisic, Aleksandar2-Mar-09 11:48 
Question[Message Deleted] Pin
Davitor2-Mar-09 5:58
Davitor2-Mar-09 5:58 
AnswerRe: File handaling problem Pin
Richard Andrew x642-Mar-09 6:12
professionalRichard Andrew x642-Mar-09 6:12 
GeneralRe: File handaling problem Pin
Ric Ashton2-Mar-09 6:31
Ric Ashton2-Mar-09 6:31 
GeneralRe: File handaling problem Pin
Ric Ashton2-Mar-09 6:33
Ric Ashton2-Mar-09 6:33 
GeneralRe: File handaling problem Pin
Davitor2-Mar-09 6:45
Davitor2-Mar-09 6:45 
GeneralRe: File handaling problem Pin
Davitor2-Mar-09 6:42
Davitor2-Mar-09 6:42 
GeneralRe: File handaling problem Pin
Eytukan2-Mar-09 6:56
Eytukan2-Mar-09 6:56 
GeneralRe: File handaling problem Pin
Ric Ashton2-Mar-09 6:59
Ric Ashton2-Mar-09 6:59 
GeneralRe: File handaling problem Pin
Richard Andrew x642-Mar-09 7:44
professionalRichard Andrew x642-Mar-09 7:44 
AnswerRe: File handaling problem Pin
Maximilien2-Mar-09 6:53
Maximilien2-Mar-09 6:53 
GeneralRe: File handaling problem Pin
Davitor2-Mar-09 7:05
Davitor2-Mar-09 7:05 
GeneralRe: File handaling problem Pin
Maximilien2-Mar-09 7:16
Maximilien2-Mar-09 7:16 
AnswerRe: File handaling problem Pin
David Crow2-Mar-09 9:01
David Crow2-Mar-09 9:01 
QuestionConstructor / Destructor Question Pin
Richard Andrew x642-Mar-09 5:15
professionalRichard Andrew x642-Mar-09 5:15 
AnswerRe: Constructor / Destructor Question Pin
«_Superman_»2-Mar-09 5:31
professional«_Superman_»2-Mar-09 5:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.