具有初始化器列表的向量的位置 [英] Emplacement of a vector with initializer list
本文介绍了具有初始化器列表的向量的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 std :: vector< std :: vector< double>>
,并希望在它的末尾添加一些元素, :
i have a std::vector<std::vector<double>>
and would like to add some elements at the end of it so this was my trial:
std::vector<std::vector<double> > vec;
vec.emplace_back({0,0});
但这不会编译,而下面会做:
but this does not compile whereas the following will do:
std::vector<double> vector({0,0});
为什么emplace_back不能在这个位置构造元素?
Why can't emplace_back construct the element at this position? Or what am i doing wrong?
推荐答案
感谢您的帮助。 p>模板扣除不能猜测你的括号包含的初始化列表应该是一个向量。您需要明确:
Template deduction cannot guess that your brace-enclosed initialization list should be a vector. You need to be explicit:
vec.emplace_back(std::vector<double>{0.,0.});
这篇关于具有初始化器列表的向量的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文