I understand the main problem when passing the address of a member function outside of my class. I get the feeling that mem_fn () might be the solution, but I'm having problems with specifics.
I have a member function in class p that is currently declared as
typedef void (*valNamedFlagsCallback)(const int, const bool); bool valNamedFlags(const OptBlk *operand, const char *description_of_value_or_NULL, const int subscripts[], const char *names[], valNamedFlagsCallback callBack);
In class e, I'm trying to call valNamedFlags with
pInstance->valNamedFlags(operand, "Statement types", statementsSubscripts, statementsNames, std::mem_fn(&e::setStatement));
(I started without mem_fn (), but of course I have classic problems with pointers to member functions. I tried using both parameters: amer; e :: setStatement and just plain & setStatement.)
FWIW, setStatement is prototyped as
void setStatement(const int ifcid, const bool isAffirmative);
Everything works if I exclude mem_fn () and declare setStatement static. I simply point out that this is a way of saying that I eliminated all other possible problems; my only problem is the "member function pointers" problem. Unfortunately, setStatement () must be a member function, not static.
The specific error that I get in MS VS 2010 is
bool p :: valNamedFlags (const OptBlk *, const char *, const int [], const char * [], p :: valNamedFlagsCallback) ': cannot convert parameter 5 from' std :: tr1 :: _Mem_fn3 <_Rx, _Pmf , _Arg0, _Arg1, _Arg2> 'to' p :: valNamedFlagsCallback '
I would like to keep the callback declaration independent of class e; that is, I do not want to go to
typedef void (*e::valNamedFlagsCallback)(const int, const bool);
because I want to keep p more generalized than that.
Is mem_fn () the right solution or am I not in the database? If so, how should I declare a callback in the valNamedFlags () prototype?
Or should I take a different approach?