How to invoke a member function pointer?

Discussion in 'C++' started by Maximus, Aug 28, 2008.

  1. Maximus

    Maximus Guest

    I need to store a member function pointer as a class member, code below:

    struct Struct_Type
    {
    typedef int (Struct_Type::*FuncType)(int, int);
    FuncType funcA;

    int func1(int a, int b) { return a+b+c;}
    int func2(int a, int b) { return a-b+c; }
    int func3(int a, int b) { return a*b+c; }

    int c;
    };

    //Struct_Type value1 = {0, 1 };
    Struct_Type value2;
    //FuncType funcA = &Struct_Type::func2;

    Struct_Type value = {NULL, 10 };
    Struct_Type value3 = {&Struct_Type::func3, 100 };

    However, when I invoked the member, the compiler (VS 2005) gave me an error:

    std::cout << (value3.*funcA)(20, 10);

    error C2065: 'funcA' : undeclared identifier

    Thanx in advance.
    Maximus, Aug 28, 2008
    #1
    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. christopher diggins
    Replies:
    7
    Views:
    2,062
    christopher diggins
    Feb 13, 2004
  2. Fraser Ross
    Replies:
    4
    Views:
    1,043
    Fraser Ross
    Aug 14, 2004
  3. Immortal Nephi
    Replies:
    1
    Views:
    398
    Victor Bazarov
    May 8, 2009
  4. , India
    Replies:
    3
    Views:
    550
    James Kanze
    Aug 26, 2010
  5. somenath
    Replies:
    2
    Views:
    156
    somenath
    Aug 29, 2013
Loading...

Share This Page