I\'ve been struggling for hours with the same part of the code, and I cannot find any answer that can guide me.
I\'m using a library, and a method requires to pass a cal
Member functions take *this
pointer as a first parameter, so your function signature is actually:
void(HouseKeeper*, char*, uint8_t*, unsigned int)
While std::function in library setCallback function takes:
std::function<void(char*, unsigned char*, unsigned int)>.
You have to change your uint8_t*
to unsigned char*
in your callback second parameter (thanks Daniel H), and also get rid of implicit *this
.
You can use std::bind to bind *this
pointer to match setCallback() signature:
std::function<void(char*, uint8_t*, unsigned int)> yourFunction = std::bind(&HouseKeeper::callback, this, _1, _2, _3);
library.setCallback(yourFunction);
Or wrap your call in lambda function:
std::function<void(char*, uint8_t*, unsigned int)> yourFunction = [=](char* topic, uint8_t* payload, unsigned int length) {
this->callback(topic, payload, length);
}
library.setCallback(yourFunction);
The "classic" way to use callbacks is to declare your callback function static.