How to invoke a member function pointer?

M

Maximus

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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top