From: "Steven S. Falls" Newsgroups: comp.os.msdos.djgpp Subject: Re: Function Pointer Problem Date: Tue, 22 Dec 1998 12:04:29 -0800 Content-Transfer-Encoding: 7bit References: <367F672B DOT E7A3F4CA AT earthlink DOT net> <367f982c DOT 23433981 AT news DOT snafu DOT de> X-Posted-Path-Was: not-for-mail Content-Type: text/plain; charset=us-ascii X-ELN-Date: 22 Dec 1998 20:01:22 GMT X-ELN-Insert-Date: Tue Dec 22 12:05:04 1998 Organization: EarthLink Network, Inc. Lines: 122 Mime-Version: 1.0 NNTP-Posting-Host: ip254.san-francisco23.ca.pub-ip.psi.net Message-ID: <367FFB4D.DE5C6EFC@earthlink.net> X-Mailer: Mozilla 4.02 [en]C-DIAL (Win95; U) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com What if a function requires a "normal" fuction pointer but I need to give it a function from a class. fo ex. #include #include "fgraphwa.h" //My windowing GUI library for DJGPP avalible soon when I get these //bugs finished class HelloClass { private: MSGHANDLE Hello_Message,Exit_Message; WINHANDLE Hello_Window; BTNHANDLE Hello_Button; void Hello_Button_Action_Proc(void); void Hello_Button_Static_Proc(void); void Hello_Proc(void); public: HelloClass(void); }; void HelloClass::Hello_Button_Action_Proc(void) { exit(0); } void HelloClass::Hello_Button_Static_Proc(void) { type_btnnode *ThisBtn; ThisBtn=Api_Interface.info_button(Hello_Button); if(ThisBtn->PressDown) { Graphix.Draw_Filled_Box(20,25,70,35,22); //Draws Button Background Based On The Current Window Cordinats Graphix.Draw_VLine(20,25,35,25); //Draws Button Backgraound Graphix.Draw_HLine(20,35,71,25); //Draws Button Background Graphix.Draw_VLine(71,25,35,20); //Draws Button Background Graphix.Draw_HLine(20,25,71,20); //Draws Button Background Api_Interface.display_message(Api_Interface.info_message(Exit_Message)); //Displayes Exit Message }else{ Graphix.Draw_Filled_Box(20,25,70,35,25); //Draws Button Background Based On The Current Window Cordinats Graphix.Draw_VLine(20,25,35,22); //Draws Button Backgraound Graphix.Draw_HLine(20,35,71,22); //Draws Button Background Graphix.Draw_VLine(71,25,35,28); //Draws Button Background Graphix.Draw_HLine(20,25,71,28); //Draws Button Background Api_Interface.display_message(Api_Interface.info_message(Exit_Message)); //Displayes Exit Message } } void HelloClass::Hello_Proc(void) { Graphix.Set_Drawing_Window(Api_Interface.info_window(Hello_Window)); //Set Graphics Drawing To This Window Graphix.Clear_Window(); //Clears Window Api_Interface.display_message(Api_Interface.info_message(Hello_Message)); //Displayes Hello World Message Api_Interface.display_buttons(Hello_Button,Hello_Window); //Tests If Button Has Been Clicked And If It Has It Runs The Action Graphix.Copy_Window(Api_Interface.info_window(Hello_Window)); //Copys Window to the Ram Page Graphix.Set_Drawing_Screen(); //Sets Graphics Drawing to the Ram Page } HelloClass::HelloClass(void) { Hello_Window=Api_Interface.new_window(260,175,110,50,(void (*) ())Hello_Proc); //Make New Window Hello_Button=Api_Interface.new_button(20,25,50,10,15,(void (*) ())Hello_Button_Action_Proc,(void (*) ())Hello_Button_Static_Proc);//Make New Button Hello_Message=Api_Interface.new_message(10,5,"Hello World",109,49); //Make New Message Exit_Message=Api_Interface.new_message(30,27,"Exit",70,35); //Make New Message } void main(void) { Api_Interface.load_gui_font("default.fnt"); //Load Font HelloClass HelloWorld; for(int a=0;a<2;a++) { //Make An Endless Loop a=0; Graphix.Clear_Ram_Page(); Api_Interface.display_windows(); //Display All windows Io_Interface.Display_Mouse_Pointer(); Graphix.Copy_Ram_Page(); //Copy Ram Page To The Screen } } Thnaks Ardy Horst Kraemer wrote: > On Tue, 22 Dec 1998 01:32:27 -0800, "Steven S. Falls" > wrote: > > > Hi I am trying to get a fuction pointer point to another part of a > > class. It compiles but it does not run properly. Any ideas why? and how > > to solve the problem? > > [...snipped...] > > Pointers to non-static member functions of a class have nothing to do > with "normal" pointers to functions. > > They have to evoked with a special syntax .* or ->* including the > object through which they are called. > > Example > > #include > > struct X { > void (X::*fp)(); // declares a pointer to a non-static member > // function of X > void f(void) { cout << "hello" << endl; } > X() { fp = &X::f; (this->*fp)(); } > }; > > int main() > { > X x; > return 0; > } > > Regards > Horst