Hello together!
I know this is more a programming question than a arduino specific issue, but I've been through some C++ tutorials and I can't find a solution the compiler finds acceptable. However I hope this is an easy thing for you programming pros here Actaually I think I know what I want, but this seems to be a syntax problem...
Well, I try to create a class for all my wifi and server function on an ESP8266 and within this class I want to create an object for the webserver. Usually I could create a global object called "server" and webSocket and use it, which works fine, very simple thing:
#include <ESP8266WiFi.h>Â Â Â Â // Include the Wi-Fi library
#include <ESP8266WebServer.h>Â // Include the WebServer library
#include <FS.h>Â Â Â Â Â Â Â Â // Include the SPIFFS library
#include <WebSocketsServer.h>Â
ESP8266WebServer server(80);Â Â Â // Create a webserver object that listens for HTTP request on port 80
WebSocketsServer webSocket(81);Â Â // create a websocket server on port 81
Now I would like to encapsulate this all a bit and create my server objects within a class:
class Wifi{
 private:
  ESP8266WebServer server(80);   // Create a webserver object that listens for HTTP request on port 80
  WebSocketsServer webSocket(81);  // create a websocket server on port 81
 public:
  Wifi(void);      //Constructor
};
However the compiler doesn't like this at all, it says "Wifi.h:27:29: error: expected identifier before numeric constant" Obviously I am not allowed to initialize my objects in the declaration. Actually this would work when the objects don't need parameters, but these ones do!
So I try to move the initialization into the constructor:
class Wifi{
 private:
  ESP8266WebServer server;   // Create a webserver object that listens for HTTP request on port 80
  WebSocketsServer webSocket;  // create a websocket server on port 81
 public:
 Wifi(void);      //Constructor
};
Wifi::Wifi(void){
 ESP8266WebServer server(80);   // Create a webserver object that listens for HTTP request on port 80
 WebSocketsServer webSocket(81);  // create a websocket server on port 81Â
}
I also tried:
Wifi::Wifi(void){
 server(80);   // Create a webserver object that listens for HTTP request on port 80
 webSocket(81);  // create a websocket server on port 81Â
}
Compiler says no!
So to wrap up my question:
How do I declare my objects, that need parameters for creation, in the class definition and call their constructors in the constructor of my class later?
Sorry again to annoy you with such a stupid question, as I said I can't find anything via google about this, probably beacuse I don't know the right "buzzword".
Thank you!
Best regards
Daniel