Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Class member function pointer calling error. (http://www.velocityreviews.com/forums/t287462-class-member-function-pointer-calling-error.html)

Skavenger 12-09-2004 12:05 PM

Class member function pointer calling error.
 
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.


Rob Williscroft 12-09-2004 12:44 PM

Re: Class member function pointer calling error.
 
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/


All times are GMT. The time now is 06:23 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.