Class member function pointer calling error.

S

Skavenger

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.
 
R

Rob Williscroft

Skavenger wrote in @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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top