Z
zaeminkr
I have class member data which is a pointer to class member function.
However, I'm fail to compile the code.
What is the correct grammar to make a function call by using static
member data which is a pointer to a member function?
class Test
{
public :
typedef int (Test::*pfnOperate)(int x, int y);
static const pfnOperate m_arpOperate[2];
public :
int Add(int x, int y);
int Subtract(int x, int y);
void Foo();
};
const Test:fnOperate Test::m_arpOperate[2] = {Test::Add,
Test::Subtract};
int Test::Add(int x, int y)
{
return x + y;
}
int Test::Subtract(int x, int y)
{
return x - y;
}
void Test::Foo()
{
int result;
result = (Test::m_arpOperate[1])(10, 5); // error C2064: term does
not evaluate to a function
}
int main(int argc, char* argv[])
{
Test t;
t.Foo();
return 0;
}
However, I'm fail to compile the code.
What is the correct grammar to make a function call by using static
member data which is a pointer to a member function?
class Test
{
public :
typedef int (Test::*pfnOperate)(int x, int y);
static const pfnOperate m_arpOperate[2];
public :
int Add(int x, int y);
int Subtract(int x, int y);
void Foo();
};
const Test:fnOperate Test::m_arpOperate[2] = {Test::Add,
Test::Subtract};
int Test::Add(int x, int y)
{
return x + y;
}
int Test::Subtract(int x, int y)
{
return x - y;
}
void Test::Foo()
{
int result;
result = (Test::m_arpOperate[1])(10, 5); // error C2064: term does
not evaluate to a function
}
int main(int argc, char* argv[])
{
Test t;
t.Foo();
return 0;
}