Error: 'String' does not name a type

I’m getting an error while trying to comple the following code in the web IDE

indent preformatted text by 4 spaces
#ifndef UBERDAY
#define UBERDAY
#include <string.h>

class Day{
    String dayOfTheWeekString();
    int hour();
    int minute();
    String doftw;
    int h;
    int m;

compiler error is as follows:

In file included from Day.cpp:1:0:
Day.h:8:9: error: 'String' does not name a type
String dayOfTheWeekString();
Day.h:12:9: error: 'String' does not name a type
String doftw;
Day.cpp:8:1: error: 'String' does not name a type
String Day::dayOfTheWeekString(){
make: *** [Day.o] Error 1

Syntax appears to be correct, is this an IDE issue? Thanks in advance!

Hi @ubergeek82

If you have a .cpp file in the web IDE it does not use the Spark preprocessor, so you need to #include "application.h"

1 Like

That worked, thanks!

1 Like

@bko is it advised to programming OOP in Spark? I have worked with Arduino and while it’s completely ok to write classes, I was told not to since it can easily overrun the memory.

Heya @metaculus,

You have more ram and flash space for your programs, so I think it’s a bit safer to do OOP here. :slight_smile:


1 Like

Hi @metaculus

OO and Classes are great on Spark! But you are writing C++ and not using the wiring/Arduino pre-processor. That means that you have follow all the C/C++ rules for classes, function prototypes etc.

As @Dave says, the memory here for both code and data is better, so it will be fine. Just remember you are on a resource limited platform and if you are creating and destroying objects quickly (like the Arduino String substring method does for instance) then you can run out of memory since no garbage collector is perfect. Static memory allocation works a lot better on resource limited platforms since you the programmer have full control and full responsibility.

@bko that’s good to know. However, is there a performance difference between writing as .ino (using arduino pre-processor) and .cpp and including application.h (using C++ pre-processor), provided I’m not writing OO and not doing any malloc operations?


Hi @metaculus

No, these are compiled by the same compiler in the same way. The Arduino-style preprocessor just makes it easier to ignore some programming details that you have to pay attention to when writing C/C++.