Non-static member function as callback for espconn_regist_connectcb
Posted: Fri Jul 14, 2017 6:37 am
Hi guys, I'm new to the ESP32 world and just started working with the NONOS-SDK.
I'm writing my own libraries in c++ and got stuck trying to define the callbacks for a few network events. I've been trying to find ways around it but no luck so far.
Normally in C you would do:
But since my callback is a member function I'm obviously getting a compilation error (error: converting from 'void (FooClass::*)(void*)' to 'espconn_connect_callback {aka void (*)(void*)}')
Is there any c++ expert out there that could throw some light on this? I basically need the following (or similar) to work:
Any help would be greatly appreciated!
A.
I'm writing my own libraries in c++ and got stuck trying to define the callbacks for a few network events. I've been trying to find ways around it but no luck so far.
Normally in C you would do:
Code: Select all
void onConnected(void *args){...}
void connect(){
struct espconn *conn = (struct espconn *) os_zalloc(sizeof(struct espconn));
// ...
espconn_regist_connectcb(conn, (espconn_connect_callback) onConnected);
}
Is there any c++ expert out there that could throw some light on this? I basically need the following (or similar) to work:
Code: Select all
void FooClass::onConnected(void *args){...}
void FooClass::connect(){
struct espconn *conn = (struct espconn *) os_zalloc(sizeof(struct espconn));
// ...
espconn_regist_connectcb(conn, (espconn_connect_callback) onConnected);
}
A.