Hi,
I am struggling how to use a class that I defined in a .cpp file.
I am using Arduino IDE 1.8.15, the sample test project that I have created compile fine but the linker complain.
I have tryed to create a folder in the arduino library folder named it "MyClass" and inside I have put two files: MyClass.h and MyClass.cpp. Then I have created a test.ino sketch where I have instantiated an object of type MyClass and used a class method inside the setup function.
You have the declaration of MyClass::MyClass() inside the .h file so it gets declared in both of the places that MyClass.h is included. Change MyClass.h to this:
Alternatively, you can move the definition of MyClass::MyClass() to MyClass.cpp. That way it is only defined once.
Mostly it depends on how big the function is. If it is very simple, like in your example, it makes sense to put it in the class declaration. If it were more complex and would clutter up the class declaration, it would make sense to move it to the .cpp file.