From: Endlisnis Newsgroups: comp.os.msdos.djgpp Subject: Re: 3 questions Date: Tue, 27 Apr 1999 14:09:37 -0300 Organization: BrunNet Lines: 60 Message-ID: <3725EF51.99B5D049@unb.ca> References: <7g3ia8$fhm AT dfw-ixnews10 DOT ix DOT netcom DOT com> NNTP-Posting-Host: ftnts2c9.brunnet.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 [en] (Win95; U) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Ofer Nave wrote: > >2) How do I make a pointer to a class function and call it using that > >pointer? > This is a C++ question, not a DJGPP question, but the answer is that you > can't take the pointer of a member function unless it is a static member > function. See the following: That is incorrect. This compiles under DJGPP and shows how to take the address of a non-static member function and call it. Please note that you must explicitly pass the object to the function. There are some warnings which can be removed with casts, but this runs and prints what you would expect "static \n myMember bb = 42". And if you feel it is too much to separetly take care of the function pointer and the object pointer, just stick them in a struct, and make a #define which will call it correctly. #include class foo { public: int bb; void myMember( void ) ; static void myStaticMember( void ) ; } ; void foo::myMember() { printf("myMember: bb = %d", bb); } void foo::myStaticMember() { printf("static\n"); } void main( void ) { void (*ptr)() ; void (*a)(foo&); foo bar = {42}; a = bar.myMember ; ptr = bar.myStaticMember ; ptr(); a(bar); } -- (\/) Endlisnis (\/) s257m AT unb DOT ca Endlisnis AT BrunNet DOT Net Endlisnis AT HotMail DOT com ICQ: 32959047