m47h m47h - 1 year ago 87
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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download