user7117046 user7117046 - 27 days ago 14
C++ Question

Eclipse IDE Arduino (Sloeber) C++ String in class error does not name a type

In the project

.ino
file this works:

void loop()
{
String stringOne = "Hello String";
}


However, in a class I get these errors:

// MenuItem.h
//#include "String.h" ====> Makes no difference if not commented
class MenuItem {
public:
MenuItem();
private:
String stringTwo; ====> 'String' does not name a type
};


// MenuItem.cpp
//#include "String.h" ====> Makes no difference if not commented
MenuItem::MenuItem() {
stringTwo = "Goodbye String"; ===> 'stringTwo' was not declared in this scope
}


I've tried different option for the
#include
with
<>
instead of quotes and with without the
.h.
I'm totally confused. Thanks.

Answer

The String class for Arduino is held in the WString.h and WString.cpp files.

You should just include WString.h in your .h file. The Arduino IDE automatically does this for your .ino files.