I am programming an Arduino. In the same .ino file as setup()
and loop()
I have defined the following:
void setup()
{
// setup code
}
enum class CYCLE { TypeA, TypeB };
String cycleToString (CYCLE cycle) {
if (cycle == CYCLE::TypeA) {
return "TypeA";
}
else if (cycle == CYCLE::TypeB) {
return "TypeB";
}
return "Undefined";
}
void loop()
{
// loop code
}
But on compiling it gives the error:
sketch_v1:37:22: error: 'CYCLE' was not declared in this scope
String cycleToString (CYCLE cycle) {
^
/Users/.../sketch_v1.ino: In function 'String cycleToString(CYCLE)':
sketch_v1:37:31: error: 'String cycleToString(CYCLE)' redeclared as different kind of symbol
String cycleToString (CYCLE cycle) {
^
/Users/.../sketch_v1.ino:37:8: note: previous declaration 'String cycleToString'
String cycleToString (CYCLE cycle) {
^
Note that the enum class
is fine and works as intended but if I try to add the function relying on the CYCLE
type it then errors.
enum class
instead of justenum
?enum class
orenum struct
from C++11 is enum where the values can be used only with the enum type name likeCYCLE::TypeB
.setup()
-loop()
template and it works!