Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Molda
#25884 Hi
could someone please help me a bit.

I need to pass a class member function to server.on, unfortunately i get na error.
error: no matching function for call to 'ESP8266WebServer::on

This works:
void handleRoot(){}
server.on("/", handleRoot);

This doesn't:
void myClass::handleRoot(){}
void myClass::setup(){
server.on("/", handleRoot);
}

Why does this not work?

Thank you for any help
User avatar
By martinayotte
#25894 Maybe you should show the whole code, for example, how do you instantiate your myClass object.
Because you needs to pass your myClass::handleRoot() callback function to server.on() function properly.
User avatar
By Molda
#25904 Thanks for your comment.
There isn't much more to it really

myClassTest.ino
Code: Select all#include <ESP8266Wifi.h>
#include <ESP8266WebServer.h>
#include "myClass.h"

void setup(){}
void loop(){}


myClass.h
Code: Select allclass myClass {
  public:
    void handleRoot();
    void setup();
}


myClass.cpp
Code: Select all#include <ESP8266Wifi.h>
#include <ESP8266WebServer.h>
#include "myClass.h"

ESP8266WebServer server(80);

void myClass:: handleRoot(){}
void myClass:: setup(){
  handleRoot (); // here it runs OK.
// unfortunately not when passed as argument
// it doesn't compile
  server.on("/",  handleRoot);
}


If I remove myClass:: from void myClass:: handleRoot(){} it runs ok

I don't instantiate the class in myClassTest.ino
User avatar
By igrr
#25905 You need to bind your function call to a specific MyClass instance, unless handleRoot is a static member function.
Pass std::bind(&MyClass::handleRoot, this) instead of &handleRoot.