function pointers in c++ : error: must use '.*' or '->*' to call pointer-to-member function in function -
code snippet follows. not able understand why getting error.
void sipobj::check_each_field() { map <std::string, sip_field_getter>::iterator msg; string str; char name[20]; bool res = false; sscanf(get_payload(), "%s %*s", name); loginfo(lc()) << "invite:" << name; str = name; msg = sip_field_map.find(str); if (msg != sip_field_map.end()) { sip_field_getter sip_field = msg->second; res = (this).*sip_field(); } } typedef bool (sipobj::*sip_field_getter)(); static map <std::string, sip_field_getter> sip_field_map; sip_field_getter place holder function names
(this).*sip_field();
there 2 problems expression:
this
pointer, must use->*
call member function via pointer on it.the function call (
()
) has higher precedence member-by-pointer operators (either.*
or->*
), need parentheses correctly group expression.
the correct expression is:
(this->*sip_field)();
Comments
Post a Comment