I'm reading through Programming Principles and Practice C++, and came across the following piece of code which I don't think was well explained
struct Day {
vector<double> hour{vector<double>(24,-777) };
};
What is happening here? I usually use this initializer when I need a vector of a certain length with default values:
vector<double> hour(24, -777);
However, this way of initializing does not work inside the struct,
struct Day {
vector<double> hour(24, -777);
};
Results in a compile error
Error (active) expected a type specifier HelloWorld d:\Visual Studio 2015\HelloWorld\HelloWorld\HelloWorld.cpp 11
Error (active) expected a type specifier HelloWorld d:\Visual Studio 2015\HelloWorld\HelloWorld\HelloWorld.cpp 11
Error C2059 syntax error: 'constant' HelloWorld d:\visual studio 2015\helloworld\helloworld\helloworld.cpp 11
Looking for an explanation behind the initializers.
I'm using MS Visual Studio 2015