Trying to create c++ library using EthernetServer.h

Hello,

This is pretty new to me, so bear with me. I am having trouble creating a EthernetServer class instance inside my c++ library class. When I try to compile(below), IDE is telling me that it has no matching function for 'EthernetServer::EthernetServer()' + all the derivatives. I think it is telling that I have to implement the methods of ethernetserver. I don't want to do that. Just want to use it in my class like-> aserver.begin()..etc. Can anybody offer some assistance or guidance on how to learn about this?

Thanks,

-ren

#include <EthernetClient.h>
#include <EthernetServer.h>
class myserver: public print
{
public:
.....
private:
EthernetServer aserver;

};

The class EthernetServer does not seem to have a default constructor (ie. one that takes no arguments).

  EthernetServer(uint16_t);

Thus, you can't create an instance of it like this:

EthernetServer aserver;
 #include <EthernetClient.h>
 #include <EthernetServer.h>
class myserver: public print

Notice the form of the existing class names - EachWordStartsWithAnUpperCaseLetter.

You really should follow that form.

Nick,

I understand, makes sense. I would need to initialize an instance of this class with its constructor. If ethernetserver class does not have a default w/o variable, then I need to use another one of the constructors. However, the code I was referencing uses this same techique, why does it compile successfully? Ref. https://github.com/sirleech/Webduino/blob/master/WebServer.h, excerpt below.

Paul,

Yes, thanks for the tip.

Thanks,

-ren

#include <EthernetClient.h>
#include <EthernetServer.h>

class WebServer: public Print
{public:
...
private:
EthernetServer m_server;
EthernetClient m_client;

}

Look further down. Their constructor initializes the embedded class with an initialization list. This is permitted (one constructor initializes another constructor):

WebServer::WebServer(const char *urlPrefix, int port) :
  m_server(port),   // <------------ here
  m_client(255),
  m_urlPrefix(urlPrefix),
  m_pushbackDepth(0),
  m_cmdCount(0),
  m_contentLength(0),
  m_failureCmd(&defaultFailCmd),
  m_defaultCmd(&defaultFailCmd)
{
}

Nick,

Thanks! I got it working.

-ren