Closed kokospalme closed 4 years ago
@kokospalme Thank you for using PageBuilder.
what is the problem about using Root_elm.addToken("ROOT", rootPage) ? rootPage is a non-static member of WebUI, which is used by a non-static member function?!
The problem is that the rootPage
is a non-static member. That's exactly an error. Your code is ambiguous about the instance passing to the addToken
.
You must explicitly specify the instance if you pass a non-static member function as a callback. It is a standard for Callable function objects of C++.
In this case, you need to bind the addToken
to its instance with this
identity.
Refer to:
https://stackoverflow.com/questions/37636373/how-stdbind-works-with-member-functions
https://en.cppreference.com/w/cpp/utility/functional/bind
WebUI.cpp
#include <functional>
#include "WebUI.h"
...
void WebUI::begin() { // runs in void setup()
Root_p.exitCanHandle(std::bind(&WebUI::handleAcs, this, std::placeholders::_1, std::placeholders::_2)); // Handles for all requests.
...
}
bool WebUI::handleAcs(HTTPMethod method, String uri) {
...
Root_elm.setMold(PSTR("<html>"
"<body>"
"<h2>{{ROOT}}</h2>"
"</body>"
"</html>"));
Root_elm.addToken(String("ROOT"), std::bind(&WebUI::rootPage, this, std::placeholders::_1));
return true;
...
}
thanks for your reply. I'll give it a try... :)
Closed due to no activity after providing the solution. Post the new comment to reopen.
Hello Hieromon, I really like your PageBuilder library and want to use it in my own class, which should contain the pageBuilder and pageElement objects to get things going further than in the basic *.ino-file. But now I'm stuck since 2 days... I have copied the code from DynamicPage.ino-example, but with this code in the WebUI.cpp
and this code in WebUI.c
I get this error:
what is the problem about using
Root_elm.addToken("ROOT", rootPage)
? rootPage is a non-static member of WebUI, which is used by a non-static member function?!Can you guys help me out with this?