i am taking a c++ course and the instructor said to make variables like this:
int main() {
int myVar {5};
return 0;
}
this gives me an error: "expected ";" at the end of declaration"
what is wrong?
i am taking a c++ course and the instructor said to make variables like this:
int main() {
int myVar {5};
return 0;
}
this gives me an error: "expected ";" at the end of declaration"
what is wrong?
Uniform initialization requires C++11.
If you use
g++ --std=c++11 [...]
it should work.
test> g++ foo.cpp
foo.cpp:3:6: error: expected ';' at end of declaration
int x{7};
^
;
1 error generated.
test> g++ --std=c++11 foo.cpp
test>
with
test> more foo.cpp
int main()
{
int x{7};
}