ESP8266 Developer Zone The Official ESP8266 Forum 2017-07-15T09:04:00+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=5604 2017-07-15T09:04:00+08:00 2017-07-15T09:04:00+08:00 https://bbs.espressif.com:443/viewtopic.php?t=5604&p=14593#p14593 <![CDATA[Non-static member function as callback for espconn_regist_connectcb]]>
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:

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:

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.

Statistics: Posted by alex323qp — Sat Jul 15, 2017 9:04 am


]]>