Class member function pointer calling error.

Discussion in 'C++' started by Skavenger, Dec 9, 2004.

  1. Skavenger

    Skavenger Guest

    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.
     
    Skavenger, Dec 9, 2004
    #1
    1. Advertising

  2. 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/
     
    Rob Williscroft, Dec 9, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Newsgroup - Ann
    Replies:
    5
    Views:
    610
    John Carson
    Jul 30, 2003
  2. Fraser Ross
    Replies:
    4
    Views:
    1,055
    Fraser Ross
    Aug 14, 2004
  3. Replies:
    12
    Views:
    726
    fluden
    Feb 11, 2005
  4. Praetorian
    Replies:
    11
    Views:
    2,355
    James Kanze
    Apr 3, 2008
  5. somenath
    Replies:
    2
    Views:
    160
    somenath
    Aug 29, 2013
Loading...

Share This Page