Non-static member function as callback for espconn_regist_connectcb

alex323qp
Posts: 13
Joined: Sat Jul 15, 2017 8:59 am

Non-static member function as callback for espconn_regist_connectcb

Postby alex323qp » Sat Jul 15, 2017 9:04 am

Hi guys, I'm new to the ESP8266 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:

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);
}


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:

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);
}



Any help would be greatly appreciated!

A.

Who is online

Users browsing this forum: No registered users and 64 guests