The problem here is that your function appears to be a non-static member function. Non-static member functions implicitly have additional parameter of an instance of the class they belong to, so the signatures of your std::function
and the function you are trying to pass simply don't match. However you still can bind a member function to an instance and make it compatible with the signature of a free function if needed:
AMI_MQTT instance;
std::function<void(char* topic, byte* payload, unsigned int length)> func = std::bind(&AMI_MQTT::Callback, instance, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
Alternatively you may want to get use of type erasure of lambdas:
AMI_MQTT instance;
std::function<void(char* topic, byte* payload, unsigned int length)> func = [instance] (char* topic, byte* payload, unsigned int length) {
instance.Callback(topic, payload, length);
};
Be advised, however, that instance
inside of a lambda is a copy of the instance
outside of it, so they don't share the same state.
A way more concise solution would be just making the non-static member function static, in this case you can use it without any instance bound to it:
struct AMI_MQTT {
static void Callback(char* topic, byte* payload, unsigned int length);
...
}
std::function function = AMI_MQTT::Callback;