N
neilsolent
I never did get my head round these :-(
After simplifying down for posting - I have a class CTest which is
supposed to have a static member variable called m_func, which points
to one of the two static member functions FuncA and FuncB. It is
initially set to NULL:
test.h
--------
class CTest
{
public:
static int (CTest::*m_func)(void);
static int FuncA();
static int FuncB();
};
test.c
--------
int (CTest::*m_func)(void) = NULL;
int CTest::FuncA()
{
return 1;
}
int CTest::FuncB()
{
return 2;
}
I don't think this code is right.
If I try to assign to m_func:
m_func = CTest::FuncA;
... I get compiler error: cannot convert `int ()()' to `int (CTest::*)
()' in assignment
If I try to run the function that m_func points to:
if (CTest::m_func != NULL)
{
int rc = (*CTest::m_func)();
}
... I get compiler error: invalid use of `unary *' on pointer to
member.
Can anyone help with my C++ grammar ?
After simplifying down for posting - I have a class CTest which is
supposed to have a static member variable called m_func, which points
to one of the two static member functions FuncA and FuncB. It is
initially set to NULL:
test.h
--------
class CTest
{
public:
static int (CTest::*m_func)(void);
static int FuncA();
static int FuncB();
};
test.c
--------
int (CTest::*m_func)(void) = NULL;
int CTest::FuncA()
{
return 1;
}
int CTest::FuncB()
{
return 2;
}
I don't think this code is right.
If I try to assign to m_func:
m_func = CTest::FuncA;
... I get compiler error: cannot convert `int ()()' to `int (CTest::*)
()' in assignment
If I try to run the function that m_func points to:
if (CTest::m_func != NULL)
{
int rc = (*CTest::m_func)();
}
... I get compiler error: invalid use of `unary *' on pointer to
member.
Can anyone help with my C++ grammar ?