The C++11 standard gives an opportunity to initialize a vector with an initialization list like this.
vector <int> a {3, 5, 6, 2};
I am just wondering if it is possible to initialize a vector which is a member of class in a constructor via initialization list.
I looked for such a thing but I did not find it on the Internet or here on Stack Overflow, so I thought that I should ask for it. I hope that not only I, but also others will find it useful.
I do not want to make vector a static member of a class.
The class should look like this:
class Foo
{
public:
vector <int> myvector;
//Here should be a constructor
};
It could be used like this:
Foo aa{1, 2, 3, 6, 1}; // it should initialize a vector
Foo::Foo(std::initializer_list<int> init_list) : a(init_list) {}std::initializer_list, not an initiali(s/z)er list or an "initialization list". I don't want to be pedantic for its own sake, but the Standard uses such similar terms for different things that we have no choice!