I read the principles of C ++ programming and practice and stumbled upon the following piece of code, which I think was not well explained.
struct Day {
vector<double> hour{vector<double>(24,-777) };
};
What's going on 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 initialization method does not work inside the structure,
struct Day {
vector<double> hour(24, -777);
};
Compilation Error Results
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
Look for an explanation behind the initializers.
I am using MS Visual Studio 2015
source
share