Closed
Description
My skills are kind of limited in C++. A code being better than a thousand words:
MyClass.h
#ifndef MyClass_h
#define MyClass_h
#include <WebSocketsServer.h>
#include <Hash.h>
class MyClass {
public:
MyClass();
~MyClass();
private:
WebSocketsServer* wss;
int needToAccessThisValue;
void onWsEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length);
};
#endif
MyClass.cpp
#include "MyClass.h"
MyClass::MyClass() {
this->wss = new WebSocketsServer(81);
this->wss->onEvent(/* this->onWsEvent */);
this->needToAccessThisValue = 123;
}
MyClass::~MyClass() {
delete this->wss;
}
void MyClass::onWsEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
Serial.println(this->needToAccessThisValue);
}
How can I pass onWsEvent
to the onEvent
method? I can't make onWsEvent static because I need to access properties from this function (static would not allow a this
).
Thanks!
Metadata
Metadata
Assignees
Labels
No labels