c++ - Passing member function as a callback to a template function -


i'm trying pass member function argument template function. have read threads in stackoverflow passing member functions arguments other functions. but, somehow don't simple thing work:

template <typename t> t class::registercallback(std::function<t()> callback) {   // } bool class::member() {   return true; } void class::method() {   registercallback(std::bind(&class::member, this, std::placeholders::_1)); } 

the error message receive is:

no matching member function call 'registercallback' 

i have tried solve long time. grateful if can point me out wrong.

the callback must registered not have parameters.

std::function< t() >

however, try register callback accepts single parameter.

std::bind(&class::member, this, std::placeholders::_1)

furthermore, class::member function doesn't have parameters.

try this:

class class { public:     // i'm not sure why returning 't' changed 'void'     template<typename t>     void registercallback(std::function<t()> callback)     {         //     }      void method()     {         // 'member' function doesn't have parameters '_1' removed         registercallback<bool>(std::bind(&class::member, this));     }      // callback supposed return 't' changed 'bool'     bool member()     {         return true;     } };  int main() {     class<bool> c;     c.method();      return 0; } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -