problem when trying to inherit from EthernetClient class

Hello,

I'm trying to create a new class which inherits from the EthernetClient class, in order to add some specific functions to parse http commands for my needs. And I can't manage to have it working.

Initially, I had some code such as:

void loop() {
  EthernetClient client = server.available();

  if (client) {
     get_http_request(client);

     ....
  }
}

Now, I would like to make the get_http_request() function a method of a new class which inherit from EthernetClient, like:

class MyEthernetClient : public EthernetClient {
public:
    String getHttpRequest();
};

MyEthernetClient::getHttpRequest() {
...}

And with this the above code would become somthing like:

void loop() {
  MyEthernetClient client = server.available();

  if (client) {
     cmdString = client.getHttpRequest();
     ....
  }
}

But when doing this, I get following compilation error:

error: conversion from 'EthernetClient' to non-scalar type 'MyEthernetClient' requested

So then, I tried to do:

MyEthernetClient client = (MyEthernetClient) server.available();

This time I got following compilation error:

error: no matching function for call to MyEthernetClient::MyEthernetClient(EthernetClient)

So then, I tried to add a constructor like this in my new class:

class MyEthernetClient : public EthernetClient {
public:
    MyEthernetClient (EthernetClient client) : EthernetClient() {};
    String getHttpRequest();
};

This time, I got no compilation error, but it just doesn't work as before, the "if (client) {" of the loop function just never succeeds.

Could someone explain me what is the problem in the way I try to extend the base class?

Thanks and regards,
Michael

... and sorry for the long message by the way. :slight_smile:

Ok, I found a solution, my constructor was wrong, the following is working now:

class LEDMatrixEthernetClient : public EthernetClient {
public:
    LEDMatrixEthernetClient(const EthernetClient &client) : EthernetClient(client) {};
    String getHttpRequest();
};