Hello
Please have a look at the code below, it does not compile, why?
To make it easier for you, I tried to minimize the code as much as possible:
#include <Arduino.h>
// ABSTRACT CLASS:
class CycleStepTemplate
{
public:
virtual void doStuff();
private:
String stringThatDoesntWork = "this String does not work when class has a virtual method, WHY?";
};
// CONCRETE CLASS:
class CycleStep : public CycleStepTemplate
{
public:
void doStuff() {}
void additionalObjectMethod() {}
private:
String _thisStringWorks = "This String works";
};
// CREATE AN OBJECT:
CycleStep cycleStep;
void setup(){}
void loop()
{
cycleStep.doStuff();
cycleStep.additionalObjectMethod();
}
If I remove the “virtual” keyword or uncomment the String it does work, but I want em both.
What goes wrong?
the error message is:
/tmp/ccGuJ6vD.ltrans0.ltrans.o: In function `__base_ctor ':
/home/realslimshady/loeschersketch_may03a/loeschersketch_may03a.ino:4: undefined reference to `vtable for CycleStepTemplate'
Thanks a lot for every input.
Michi