0

the code is out 0 not a address std::function::target can't get a member function although i use type bool (AAA::*)(uint32_t , uint64_t , uint32_t )

#include <functional>
#include <iostream>

#include <typeinfo>
typedef std::function<bool (uint32_t , uint64_t , uint32_t )> CheckHandler;


struct AAA {
    bool IsShouldWrite (uint32_t log_id, uint64_t uid, uint32_t priority) {}
};

int main() {
    AAA a;

    CheckHandler check_handler =std::bind(&AAA::IsShouldWrite, &a, std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
    std::cout<<check_handler.target<bool (AAA::*)(uint32_t , uint64_t , uint32_t )>();
}
  • [this question](https://stackoverflow.com/questions/10938774/get-function-pointer-from-stdfunction-when-using-stdbind) can be useful – pergy Oct 13 '17 at 13:15
  • You didn't pass a pointer-to-function to `check_handler`, so of course you can't get it back with `target()`. You passed a callable object manufactured by `std::bind` - you could get back a pointer to that object, if you manage to spell its type (possible with `decltype`). – Igor Tandetnik Oct 13 '17 at 19:02

0 Answers0