Creating class and including function calling a function in the header file

I use Arduino IDE a.o. to program the ESP8266. It has a ESP8266Wifi library and I wrote a small shell around it to have short calls to something like getURL etc. As a complete file this functions work and now I wanted to get them into a class so I can just include MyWiFi.h and have all those functions available.

Fiddling around I figured out most of it but somehow I cannot figure out how to define a function calling a function in the header file to match the one in the cpp file.

Unless needed, I won't bore you all with my complete file:

The MyWiFi.h file:

#ifndef MyWiFi_H
#define MyWiFi_H

#include <Arduino.h>

class MyWiFi {
public:
  MyWiFi();
  ~MyWiFi();
  String begin (char*, char*);
  String getURL (char*, char*);
  String getURLFullParse (char*, char*, void (*)(String));
  String getURLBodyParse (char*, char*, void (*)(String));
private:
  String getURLParse (char*, char*, bool, void (*)(String));
  void doNothing (String);
};

#endif

And to match it parts of the MyWiFi.cpp file:

#include "MyWiFi.h"
#include "ESP8266WiFi.h"

MyWiFi::MyWiFi() {
}

MyWiFi::~MyWiFi() {
}

String MyWiFi::begin (char* ssid, char* password) {
...
}

String MyWiFi::getURLParse (char* host, char* url, bool fullContent, void (*g)(String l)) {
... this is quite lengthy
}

String MyWiFi::getURLFullParse (char* host, char* url, void (*g)(String l)) {
  return getURLParse(host,url,true,g);
}

String MyWiFi::getURLBodyParse (char* host, char* url, void (*g)(String l)) {
  return getURLParse(host,url,false,g);
}

String MyWiFi::getURL (char* host, char* url) {
  return getURLParse(host,url,false,doNothing);
}

The error messages I get:

C:\..\Arduino\libraries\MyWiFi\MyWiFi.cpp: In member function 'String MyWiFi::getURL(char*, char*)':

C:\..\Arduino\libraries\MyWiFi\MyWiFi.cpp:64:46: error: no matching function for call to 'MyWiFi::getURLParse(char*&, char*&, bool, <unresolved overloaded function type>)'

   return getURLParse(host,url,false,doNothing);

                                              ^

C:\..\Arduino\libraries\MyWiFi\MyWiFi.cpp:64:46: note: candidate is:

C:\..\Arduino\libraries\MyWiFi\MyWiFi.cpp:21:8: note: String MyWiFi::getURLParse(char*, char*, bool, void (*)(String))

 String MyWiFi::getURLParse (char* host, char* url, bool fullContent, void (*g)(String l)) {

        ^

C:\..\Arduino\libraries\MyWiFi\MyWiFi.cpp:21:8: note:   no known conversion for argument 4 from '<unresolved overloaded function type>' to 'void (*)(String)'

exit status 1
Error compiling for board Generic ESP8266 Module.

I'm sure it's something rather silly but this is my first C++ class so forgive me any stupidities....

c++ does not allow taking a pointer to a non-static class member function....

Regards,
Ray L.

c++ does not allow taking a pointer to a non-static class member function....

What that means is that C++ won't allow you to pass doNothing() as the function, because it has no idea which instance's doNothing() method should do nothing.

If you make doNothing() a static function, then you can use it the way you are trying to.

But, then it won't have access to any instance's data...

RayLivingston:
c++ does not allow taking a pointer to a non-static class member function....

Regards,
Ray L.

Incorrect. You can make a member-function-pointer variable, but they don't work like regular function pointers. They have a totally different syntax and need to be called on a class instance.

Jiggy-Ninja:
Incorrect. You can make a member-function-pointer variable, but they don't work like regular function pointers. They have a totally different syntax and need to be called on a class instance.

I think you misunderstood.... You cannot initialize a function pointer to point to a non-static member function as he was attempting to do.

Regards,
Ray L.