Click here to Skip to main content
15,924,367 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: 3D Game Engine Architecture's web Pin
BEamer9-Apr-06 3:07
BEamer9-Apr-06 3:07 
QuestionFile Icon Pin
big_denny_2008-Apr-06 23:38
big_denny_2008-Apr-06 23:38 
AnswerRe: File Icon Pin
Hamid_RT9-Apr-06 0:05
Hamid_RT9-Apr-06 0:05 
AnswerRe: File Icon Pin
RChin9-Apr-06 1:07
RChin9-Apr-06 1:07 
Questionintellisense with directx Pin
blue_rabbit8-Apr-06 20:59
blue_rabbit8-Apr-06 20:59 
AnswerRe: intellisense with directx Pin
Trollslayer8-Apr-06 22:56
mentorTrollslayer8-Apr-06 22:56 
Questionpointer to function in class Pin
blue_rabbit8-Apr-06 20:43
blue_rabbit8-Apr-06 20:43 
AnswerRe: pointer to function in class Pin
Matt Godbolt8-Apr-06 22:43
Matt Godbolt8-Apr-06 22:43 
The syntax for member function pointers is rather confusing. If you want to get your code compiling so as you can call 'display_1', try:
int global_display(){
	cout<<"global_display()"<<endl;
	return 0;
};
class test{
public:
	test();//constructor
	int (test::*myfun)();//the pointer_to_function
	int display1();//the member function
	int maindisplay();
};
int test::display1(){
	cout<<"display1()"<<endl;
	return 0;
};
int test::maindisplay(){
	(this->*myfun)();
	return 0;
};
test::test(){
	myfun = &test::display1;
	//myfun = global_display;
};


The main changes: firstly the constructor should not return 'int'. Then, the member function's declaration has to change to show it's a member function and not a non-member function. The invocation also has to change to use the ->* operator (or .* if you were calling a reference, in this case the object itself is calling, so we have to use this->*). Finally, the function reference has to be bound with the ampersand, and the classname too. This code was tested in VS2005 and VS2003.

Matt Godbolt
Engineer, ProFactor Software
StyleManager project
Questionvc++ Pin
sudeep_br8-Apr-06 15:43
sudeep_br8-Apr-06 15:43 
AnswerRe: vc++ Pin
EvScott8-Apr-06 16:36
EvScott8-Apr-06 16:36 
GeneralRe: vc++ Pin
sudeep_br9-Apr-06 4:31
sudeep_br9-Apr-06 4:31 
GeneralRe: vc++ Pin
EvScott9-Apr-06 5:30
EvScott9-Apr-06 5:30 
GeneralRe: vc++ Pin
sudeep_br9-Apr-06 18:01
sudeep_br9-Apr-06 18:01 
GeneralRe: vc++ Pin
Hamid_RT9-Apr-06 20:04
Hamid_RT9-Apr-06 20:04 
AnswerRe: vc++ Pin
Michael Dunn8-Apr-06 16:38
sitebuilderMichael Dunn8-Apr-06 16:38 
AnswerRe: vc++ Pin
sheshidar9-Apr-06 6:36
sheshidar9-Apr-06 6:36 
GeneralRe: vc++ Pin
sudeep_br9-Apr-06 18:03
sudeep_br9-Apr-06 18:03 
AnswerRe: vc++ Pin
David Crow10-Apr-06 3:48
David Crow10-Apr-06 3:48 
QuestionDLL to VB callback help Pin
borono8-Apr-06 13:56
borono8-Apr-06 13:56 
AnswerRe: DLL to VB callback help Pin
Michael Dunn8-Apr-06 15:14
sitebuilderMichael Dunn8-Apr-06 15:14 
GeneralRe: DLL to VB callback help Pin
borono8-Apr-06 16:02
borono8-Apr-06 16:02 
GeneralRe: DLL to VB callback help Pin
Michael Dunn8-Apr-06 16:34
sitebuilderMichael Dunn8-Apr-06 16:34 
GeneralRe: DLL to VB callback help Pin
borono8-Apr-06 17:20
borono8-Apr-06 17:20 
GeneralRe: DLL to VB callback help Pin
Waldermort8-Apr-06 20:14
Waldermort8-Apr-06 20:14 
GeneralRe: DLL to VB callback help Pin
Waldermort8-Apr-06 20:24
Waldermort8-Apr-06 20:24 

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.