Calling external function from a class function I'll try to explain my need:


I have a generic library I created, called myIOT.h.
This class have a pre-configured  MQTT and wifi setup.
Inside this library there is a mqtt_callback function, for all generic commands, such as boot_time and connection_status.
BUT, this library serves in several of my iot device's code, that each one has a few more mqtt commands, that is tailored just for s specific device, and I looking for a way that iot.mqtt_callback(ext_mqtt_func) will get as parameter a local ( which belong to the sketch and not to the library ), that will have the additional code needed.


I'll try to explain more clearly:

void myIOT::mqtt_callback(ext_mqtt_func){
if (a == true ) {
do something

};

else {

ext_mqtt_func()); // calling another fucntion that belongs to sketch and not library

}
Yes, you can do it.

You pass function pointer as function parameter.

See this stackoverflow question:

https://stackoverflow.com/questions/2582161/c-function-pointer-as-parameter