-->
Page 1 of 1

Constructor problem with class

PostPosted: Wed May 03, 2023 3:21 am
by wogoos
Hi,
I have a problem with a class constructor
This is the header part

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiServer.h>
#include <WiFiClient.h>

class stdio_handler {

public:
enum IOports {  SERIAL_IO, ATMEGA_IO, TCP_IO, FILE_IO };
            stdio_handler();
            stdio_handler(uint16_t);

uint16_t       printf(const char*, ... );
uint16_t       printf(IOports, const char*, ... );
uint16_t       printf(IOports, const char*, va_list );

uint16_t      scanf(const char* , ... );
uint16_t      scanf(IOports, const char* , ... );
uint16_t      scanf(IOports, const char* , va_list );

IOports         get_state();
size_t         available();
uint8_t         connect();

private:
WiFiClient       TCPclient;
WiFiServer       TCPserver;
File         fh;
IOports         IOprt= SERIAL_IO;

protected:
};


And this the constructor
Code: Select allstdio_handler::stdio_handler() {
   TCPserver.begin(8888);
}

stdio_handler::stdio_handler(uint16_t port) {
   TCPserver.begin(port);
}
 

I want to initialize a WIFIserver class TCPserver with a port address
When I compile the code I have two errors at the two lines (51,55)
51 stdio_handler::stdio_handler()
55 stdio_handler::stdio_handler(uint16_t port)

The errors are:
include/stdio_handler.h:51:48: error: no matching function for call to 'WiFiServer::WiFiServer()'
include/stdio_handler.h:55:48: error: no matching function for call to 'WiFiServer::WiFiServer()'

What am I doing wrong

Re: Constructor problem with class

PostPosted: Thu May 04, 2023 8:57 am
by rooppoorali
You can try the following.
Code: Select all  stdio_handler::stdio_handler() : TCPserver(8888) {
  // Other constructor code...
}

stdio_handler::stdio_handler(uint16_t port) : TCPserver(port) {
  // Other constructor code...
}