I'm new to programming and teaching myself C++ with Bjarne's book, C++11 version. I'm using Coderunner 2 with Xcode command-line tools installed on OS X El Cap. I get errors for the following code when creating variables using initializer lists. My belief is Coderunner isn't running c++11. I'm a complete novice and I don't know what to do for the life of me. Helpful advice is appreciated. Thank you in advance.
clang version: Apple LLVM version 7.0.0 (clang-700.0.72)
#include <iostream>
#include <complex>
#include <vector>
using namespace std;
int main(int argc, char** argv)
{
double d1 = 2.3; //Expressing initialization using =
double d2{2.3}; //Expressing initialization using curly-brace-delimited lists
complex<double> z = 1;
complex<double> z2{d1,d2};
complex<double> z3 = {1,2};
vector<int> v{1,2,3,4,5,6};
return 0;
}
I get the following error:
2.2.2.2.cpp:9:11: error: expected ';' at end of declaration
double d2{2.3}; //Expressing initialization using curly-brace-delimited lists
^
;
2.2.2.2.cpp:12:20: error: expected ';' at end of declaration
complex<double> z2{d1,d2};
^
;
2.2.2.2.cpp:13:18: error: non-aggregate type 'complex<double>' cannot be initialized with an initializer list
complex<double> z3 = {1,2};
^ ~~~~~
2.2.2.2.cpp:15:15: error: expected ';' at end of declaration
vector<int> v{1,2,3,4,5,6};
^
;
4 errors generated.