I am trying to push many function pointer into a vector for later use. However, I run into problems of type problem
/// in the h file
typedef std::function<int(unsigned char *)> func_t;
class A
{
void init();
// after some codes declaration
private:
B b;
std::vector<func_t> func_list;
}
class B
{
int somefunction(unsigned char *);
}
// elsewise in the cpp file of class A
A::init()
{
func_t f = std:bind(&B::somefunction, &b, std::placeholders::_1);
func_list.push_back(f);
}
The error seem to occur at the point of std::bind, the error read as
initializing: cannot convert from 'std::Binder<std::Unforced, void(__thiscall B::*)(unsigned char *), B*, const std::_Ph<1> &>' to std::function<int(unsigned char*)>
The problem goes away if I change the variable f from func_t
to auto
. Though subsequently I would have the same problem to push into the vector func_list. So I guess my problem is with the type definition or std::bind definition
Thanks