m47h m47h - 10 months ago 43
C++ Question

Emplacement of a vector with initializer list

i have a

and would like to add some elements at the end of it so this was my trial:

std::vector<std::vector<double> > vec;

but this does not compile whereas the following will do:

std::vector<double> vector({0,0});

Why can't emplace_back construct the element at this position? Or what am i doing wrong?

Thanks for your help.

Answer Source

Template deduction cannot guess that your brace-enclosed initialization list should be a vector. You need to be explicit: