| www.delorie.com/archives/browse.cgi | search |
| From: | "Michael Stewart" <mike AT reggin DOT freeserve DOT co DOT uk> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: 3 questions |
| Date: | Tue, 27 Apr 1999 07:34:23 +0100 |
| Organization: | Customer of Planet Online |
| Lines: | 67 |
| Message-ID: | <7g3ltk$kfm$1@news6.svr.pol.co.uk> |
| References: | <oo5V2.119790$Mb DOT 45033755 AT newscontent-02 DOT sprint DOT ca> <7g3ia8$fhm AT dfw-ixnews10 DOT ix DOT netcom DOT com> |
| NNTP-Posting-Host: | modem-83.glucophage.dialup.pol.co.uk |
| X-Trace: | news6.svr.pol.co.uk 925194996 20982 62.136.69.211 (27 Apr 1999 06:36:36 GMT) |
| NNTP-Posting-Date: | 27 Apr 1999 06:36:36 GMT |
| X-Complaints-To: | abuse AT theplanet DOT net |
| X-Newsreader: | Microsoft Outlook Express 4.72.3110.5 |
| X-MimeOLE: | Produced By Microsoft MimeOLE V4.72.3110.3 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
Ofer Nave wrote in message <7g3ia8$fhm AT dfw-ixnews10 DOT ix DOT netcom DOT com>...
>
>Jay wrote in message ...
>>I've got 3 questions to ask.
>>
>>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:
>
>class foo
>{
> public:
> void myMember( void ) ;
> static void myStaticMember( void ) ;
>} ;
>
>void main( void )
>{
> void * ptr ;
> foo bar ;
>
> ptr = (void *) bar.myMember ; // this doesn't work
> ptr = (void *) bar.myStaticMember ; // this works
> ptr = (void *) foo::myStaticMember ; // this works
>}
You can however create a function pointer to a member of the same class:
class test {
public:
bool (*test_func) (int var); // Function pointer
void test_func_1 (int var);
void test_func_2 (int var);
void choose_func (int func);
}
void test_func_1 (int var) {
// Do stuff
}
void test_func_2 (int var) {
// Do some more
}
void choose_func (int func) {
if (func ==1) {
test_func = &test_func_1;
} else {
test_func = &test_func_2;
}
}
--
Michael Stewart
www.freeserve.co.uk
mike AT reggin DOT freeserve DOT co DOT uk
"Just because you're paranoid doesn't mean they aren't after you..."
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |