Quick overview of how I got to this.
- Created the structure
- Created the .cpp file
- Used CMake to create Make file
- Ran Make and received error
I'm trying to compile the following code:
#include <iostream>
using namespace std;
enum UnitType { Meter, Inch };
class Meter {
double value;
public:
Meter(double value) : value(value) {}
double convertTo(UnitType unit) {
if (unit == Inch) {
return value * 39.3700787;
}
};
};
int main (int argc, char *argv[])
{
try
{
Meter meter(1.0);
}
catch (int e) {
cout << "exception " << e << endl;
}
return 0;
}
but, I'm receiving the following error:
$ make [100%] Building CXX object CMakeFiles/convert-length.dir/convert-length.cpp.o /convert/length/convert-length.cpp: In function ‘int main(int, char**)’: /convert/length/convert-length.cpp:27: error: expected ‘;’ before ‘meter’ make[2]: *** [CMakeFiles/convert-length.dir/convert-length.cpp.o] Error 1 make[1]: *** [CMakeFiles/convert-length.dir/all] Error 2 make: *** [all] Error 2
I'm hoping this is a silly C++ syntax error somewhere that I'm missing, but I've spent a couple hours looking for it with no success. I have little C++ experience, but this code looks syntactically correct. Does anyone see or know what is wrong?