Pierce Barney
Pierce Barney

Reputation: 142

Undeclared string in Arduino class

I am trying to write a class for an Arduino library. I am having a hard time getting it to allow me to pass a string variable to a method within the class.

I keep getting:

...Calc.h:21: error: 'String' has not been declared

Referring to this line of code which is line 21 in Calc.h:

void printCalc(int a, int b, String s);

I don't understand why it says that it has not been declared, because there are no problems with my int's. and I didn't do anything different with them.

Upvotes: 0

Views: 1308

Answers (2)

Igor
Igor

Reputation: 27250

Did you #include the header where String is declared? Maybe this one:

#include <WString.h>

Upvotes: 0

Jim Buck
Jim Buck

Reputation: 20726

You need to #include the header file that defines String before calc.h. calc.h should be the one to #include the header where String lives, but I see this mistake quite a bit with library developers.

Upvotes: 1

Related Questions