Inherit from Ethernet class

Hey guys,

I am building my own library and therefore I try to inherit from the Arduino Ethernet class.

MyClass.h

#ifndef MyClass_h
#define MyClass_h

#include "MyClass.h"
#include <Ethernet.h>

class MyClass: public Ethernet {

public:
MyClass();
};
#endif

MyClass.cpp

#include "MyClass.h"
#include <Ethernet.h>

MyClass::MyClass() {}

main.ino

#include <MyClass.h>

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

The compiler says in the header file: error: expected class-name before ‘{’ token

And the only advice I have found around the web is that the header file of the base class is not included, but I did or didn’t I?

Best Regards

what file and line number is the error?

Also in MyClass.h, you #include "MyClass.h". A bit pointless

check out the source code

and try adding the class name:

#ifndef MyClass_h
#define MyClass_h

#include <Ethernet.h>
#include "Arduino.h"

class MyClass: public EthernetClass {

  public:
    MyClass();
};
#endif

Got it!

The error is in MyClass.h at line 8: "class MyClass: public Ethernet {" Indeed the include of MyClass.h in itsefl is pointless. No idea why I wrote it.

My fault: The name of the class is not Ethernet. It is EthernetClass.

Thank you!

Why do you want to inherit from EthernetClass? Seems to me you’d want to inherit from EthernetServer or EthernetClient.