Cannot use "String" in abstract class when using "virtual" method

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

If you want doStuff() to be a pure virtual function, you must define it like this in the base class:

virtual void doStuff() = 0;

Regards,
Ray L.

RayLivingston:
If you want doStuff() to be a pure virtual function, you must define it like this in the base class:

virtual void doStuff() = 0;

Regards,
Ray L.

...Thanks a lot :slight_smile: that finally fixed it. Problem solved.

Stackoverflow: C++ difference between virtual = 0; and empty function

But this question still remains… why use a String object in our class? Better to use C strings.