Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Class member function pointer calling error.

Reply
Thread Tools

Class member function pointer calling error.

 
 
Skavenger
Guest
Posts: n/a
 
      12-09-2004
Hi,
I'm attempting to use a class member function pointer to call a
relevant function. This is done like this....

typedef void(SampleA::*SAMPLEAFUNC)(void);

class SampleA {
public:
SampleA() { memFunc = testFunc; }
~SampleB() {};

void testFunc (void);

SAMPLEAFUNC memFunc;
}

void main(void)
{
SampleA *a = new SampleA();

(a->*memFunc)();
}

Unfortunately I get the error C2064: Term does not evealuate to a
function when i try to call using the (a->*memFunc)(); statement.

Anyone got any idea why this is happening?
Thanks in advance.
- Skavenger.

 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      12-09-2004
Skavenger wrote in news:1102593940.551799.236980
@z14g2000cwz.googlegroups.com in comp.lang.c++:

> Hi,
> I'm attempting to use a class member function pointer to call a
> relevant function. This is done like this....
>


class SampleA; /* Meeded before the next line */

> typedef void(SampleA::*SAMPLEAFUNC)(void);
>
> class SampleA {
> public:
> SampleA() { memFunc = testFunc; }


SampleA() : memFunc( &SampleA::testFunc ) {}

> ~SampleB() {};


Did you mean ~SampleA() {}

Note the trailing ; isn't needed.

>
> void testFunc (void);
>
> SAMPLEAFUNC memFunc;
> }
>
> void main(void)
> {
> SampleA *a = new SampleA();
>
> (a->*memFunc)();


(a->*(a->memFunc))();

> }
>
> Unfortunately I get the error C2064: Term does not evealuate to a
> function when i try to call using the (a->*memFunc)(); statement.
>


BTW all upercase identifiers for eg: SAMPLEAFUNC, should be
reserved for *exclusive* use by the preprocessor (#define's), its
just a convention, but a convention *alot* of people abide by.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Member function pointer to member function of another class Praetorian C++ 11 04-03-2008 08:33 PM
What is the correct grammar to make a function call by using static member data which is a pointer to a ordinary class member function? zaeminkr@gmail.com C++ 3 07-06-2007 12:50 PM
parse error in gcc but success in vc.net, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM
Pointer-to-member-function pointing to a member function of an inherited class akiriwas@gmail.com C++ 12 02-11-2005 05:15 PM
pointer to member function and pointer to constant member function Fraser Ross C++ 4 08-14-2004 06:00 PM



Advertisments