0

I got confused while passing pointer of a class member function to a variable. this is the body of my class:

class pjsuaMyClass
{
...
private:
 pj_bool_t default_mod_on_rx_request(pjsip_rx_data *rdata);
....
};

in my application there is a structure which gets the pointer of default_mod_on_rx_request to handle the incoming messages. this structure will pass to a initiator function and may call the "on_rx_response" function.

my structure definition:

struct pjsip_module mod_default_handler
{
...
pj_bool_t (*on_rx_response)(pjsip_rx_data *rdata);
...
};

I set the value of "on_rx_response" into this:

mod_default_handler.on_rx_response = &pjsuaMyClass::default_mod_on_rx_request;

but I got following error:

pjsuamyclass.cpp:24:35: error: assigning to 'pj_bool_t (*)(pjsip_rx_data *)' (aka 'int (*)(pjsip_rx_data *)') from incompatible type 'pj_bool_t (pjsuaMyClass::*)(pjsip_rx_data *)'

what should I do to pass this function as my handler?

Scheff's Cat
  • 19,528
  • 6
  • 28
  • 56
Ahmad Afkande
  • 137
  • 2
  • 14
  • 1
    Does this answer your question? [Function pointer to member function](https://stackoverflow.com/questions/2402579/function-pointer-to-member-function) – Alan Birtles Dec 05 '19 at 11:22
  • @AlanBirtles thank you for helping, I tried it already but it did not worked, either I could not understand the sample or there is another problem. – Ahmad Afkande Dec 05 '19 at 11:24
  • 1
    Please show a [mre] of what you tried – Alan Birtles Dec 05 '19 at 11:26
  • default_mod_rx_request is a function but you're not giving it any input. So you are assigning a data member to a function – O Yahya Dec 05 '19 at 11:29
  • When someone does `mod_default_handler.on_rx_response(&something);` which instance of `pjsuaMyClass` should it call the function on? – user253751 Dec 05 '19 at 11:30
  • Just try defining, if not tried already yet, you on_rx_response object like `pj_bool_t (pjsuaMyClass::*on_rx_response)(pjsip_rx_data *rdata);` cc @Arta – v78 Dec 05 '19 at 11:43

0 Answers0