jeudi 6 septembre 2018

emplace_back of vector

I wrote one code to add element to vector>, but it failed.

vector<vector<int>> vv;
vv.emplace_back({ 1,2,3 });

But vector does container one constructor with argument of initializer_list So I changed like following:

vector<vector<int>> vv;
vv.emplace_back(initializer_list<int>{ 1,2,3 });

This compiled and succeeded, I can't figure out. Why we must explicitly use initializer_list.

Aucun commentaire:

Enregistrer un commentaire