From: "Wormy" Newsgroups: comp.os.msdos.djgpp Subject: How would I build a pointer to a method of my class Date: Sun, 8 Apr 2001 11:16:25 +0200 Organization: University of Economics and Business Administration, Vienna, Austria Lines: 69 Message-ID: <9apab3$mo7$1@bird.wu-wien.ac.at> NNTP-Posting-Host: dial-99-98.wu-wien.ac.at X-Trace: bird.wu-wien.ac.at 986721443 23303 137.208.99.98 (8 Apr 2001 09:17:23 GMT) X-Complaints-To: news-admin AT wu-wien DOT ac DOT at NNTP-Posting-Date: Sun, 8 Apr 2001 09:17:23 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hello all! In simple C, I would do something like this: ------------------------------------------- typedef void (My_func)(short parameter); My_func Pointer_to_My_func; ------------------------------------------- and then, later in my code (DOTHIS_func and DOTHAT_func are declared and defined somewhere) ------------------------------------------- if (i == 0) Pointer_to_My_func = DOTHIS_func; else Pointer_to_My_func = DOTHAT_func; (*Pointer_to_My_func)(parameter_to_pass); ---------------------------------------------- OK.... but now, how am I doing it in C++ if I'm fumbling around with a class? ------------ class CMy_class { void DOTHIS_method(short parameter); void DOTHAT_method(short parameter); void ANOTHER_method(); }; CMy_class My_class; -------------------------------- And, in the method ANOTHER_method() I would like to set the pointer to one of the two methods above (as I did it in C)... BUT I DON'T HAVE ANY IDEA HOW! I wrote down a simple pseudocode below. (NOTE: DOTHIS_method and DOTHAT_method are all methods of the same class) ------------------------------- void ANOTHER_method() { . . . if (i == 1) pointer should point to DOTHIS_method; else pointer should point to DOTHAT_method; and now call the method my pointer is pointing to . . . } ----------------------------- Can someone please give me a hint? BTW I am using VISUAL C++ 6.0 if this problem couldn't be solved in "ANSI" C++ Thanx in advance