+ 1

Function pointer for templated class method

Hi everyone, I need a hand to solve this problem, I'm trying to create a function that allows me to call a class method passed as a parameter of the aforementioned function, only that once I compile the code I get this error: src\main.cpp: In function 'void setup()': src\main.cpp:38:37: error: invalid use of non-static member function 'void esp8266webserver::ESP8266WebServerTemplate<ServerType>::handleClient() [with ServerType = WiFiServer]' 38 | b25.handler.when_connected(server.handleClient); | ~~~~~~~^~~~~~~~~~~~ In file included from ..\..\..\..\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266WebServer\src/ESP8266WebServer.h:340, from src\main.cpp:4: ..\..\..\..\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:274:6: note: declared here 274 | void ESP8266WebServerTemplate<ServerType>::handleClient() { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1st Feb 2025, 9:56 PM
Mick
Mick - avatar
9 Answers
+ 1
I'm working with esp8266 board in PlatformIO in VSCode. The line b25.handler.when_connected(callbackfunction_t callback); where typedef void(*callbackfunction_t)(void);
1st Feb 2025, 9:57 PM
Mick
Mick - avatar
0
These lines together generate the error described above.
1st Feb 2025, 9:58 PM
Mick
Mick - avatar
0
Mick , I don't know much about C++, but it'd be helpful if you link us to your code, like this: https://sololearn.com/compiler-playground/c9XEgLk7ipsR/?ref=app And, you can send us a screenshot of your error by sending us a link to your screenshot, which can be done using this website: https://imgur.com/
2nd Feb 2025, 6:55 AM
Dragon RB
Dragon RB - avatar
0
I hope you'll receive useful answers! I'm sorry I can't help you since I'm not a C++ developer.
2nd Feb 2025, 7:16 AM
Dragon RB
Dragon RB - avatar
0
code?
2nd Feb 2025, 11:38 AM
Bob_Li
Bob_Li - avatar
0
The method I am trying to pass as a parameter to this function is on line 109 of this library handleClient(); link: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WebServer/src/ESP8266WebServer.h
2nd Feb 2025, 11:45 AM
Mick
Mick - avatar
0
// orvibo_handler.h: typedef void(*callbackfunction_t)(void); // orvibo_handler.cpp: void OrviboHandler::when_connected(callbackfunction_t callback) { /* type: callbackfunction_t */ when_connected_function_pointer = callback; }
2nd Feb 2025, 11:48 AM
Mick
Mick - avatar
0
Code that generate the error: //main.cpp: b25.handler.when_connected(server.handleClient);
2nd Feb 2025, 11:49 AM
Mick
Mick - avatar
0
have you tried compiling the test example first to see if your setup runs ok?
2nd Feb 2025, 1:01 PM
Bob_Li
Bob_Li - avatar