I'm planing to use a C lib which have a function requires to register a callback function:
int add_listen(void (*listener)(const char* param));//C code
But I met a "invalid use of const_cast" error when I'm trying to do this:
class A_Interface{
public:
A_Interface():listenerCB{[this](const char* param) {
this->onReceived(std::string(param));
}} {
add_listen(listenerCB.target<void(const char*)>());
};
//will be overrided by sub class
virtual void onReceived(const std::string param) = 0;
private:
std::function<void(const char*)> listenerCB;
}
Is there any other way to pass this onReceived to add_listen?