Arduino is programmed in C++, not C. C++ doesn't use typedef for enums. Use enum TrainType { OnePeak, ... };, or even better use a scoped enum, using enum class TrainType { ... };.
At the start of compilation, the Arduino IDE makes some small changes to your .ino files to ensure it's valid C++. It will add function prototypes for any function that doesn't already have one. This is intended to make it easier for beginners to write code in the Arduino IDE, and also automates a tedious task. After inserting the function prototypes, the IDE adds #line directives so that error/warning messages will still match your sketch. In some rare cases, the Arduino IDE does not take the correct action during function prototype generation. This can lead to very confusing errors. Sometimes the error messages don't even match the code in your sketch, since the error line is the "hidden" code inserted by the Arduino IDE. When you encounter such an error, it can be very helpful to examine the post-sketch preprocessing output:
File > Preferences
Check the box next to "Show verbose output during: compilation'
Click "OK"
Sketch > Verify/Compile
After compilation fails, scroll the black console window at the bottom of the Arduino IDE window all the way to the top.
Examine the first line of output to find the value of the "-build-path" option.
You can see the problem is the function prototype for GetRandomTrainType() is being inserted above the declaration of the TrainType_e type. The Arduino sketch preproccessor only generates function prototypes for the functions that don't already have a prototype, so you can fix this sort of issue by adding a prototype at the correct location in the code (after the declaration of the TrainType_e type:
giovanniguerra:
So it it not like C++ where you can declare variables and types anywhere?
Yes and no. The compiler is regular C++. But, the Arduino IDE does some "helpful" things that in this case is messing you up due to auto-prototype generation. Your code compiles fine in Eclipse / Sloeber. In Arduino IDE, you'd need to add the function prototype:
double Test (const double x) {
double y = 1.0 / (1.0 + exp(-x)) ;
return y ;
}
enum class TrainType_e {
OnePeak,
TwoPeak,
ThreePeak,
Interpolated
};
TrainType_e GetRandomTrainType();
void setup() {
}
TrainType_e GetRandomTrainType() {
int iType = random (int(TrainType_e::OnePeak), int(TrainType_e::Interpolated) + 1) ;
return TrainType_e(iType) ;
}
void loop() {
TrainType_e a = GetRandomTrainType () ;
while (1);
}