m47h m47h - 8 months ago 38
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.


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