mercredi 30 novembre 2016

C++ Initializing a vector inside a struct definition

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, way of initializing does not work inside the struct. Looking for an explanation behind the initializers.

I'm using MS Visual Studio 2015

Aucun commentaire:

Enregistrer un commentaire