vector<vector<int> > res;
res.emplace_back({1,2}); // change to res.push_back({1,2}); would work
这给了我一个错误
main.cpp:61:25: error: no matching function for call to ‘std::vector<std::vector<int> >::emplace_back(<brace-enclosed initializer list>)’
main.cpp:61:25: note: candidate is:
In file included from /usr/include/c++/4.7/vector:70:0,
from /usr/include/c++/4.7/bits/random.h:34,
from /usr/include/c++/4.7/random:50,
from /usr/include/c++/4.7/bits/stl_algo.h:67,
from /usr/include/c++/4.7/algorithm:63,
from miscalgoc.hpp:1,
from main.cpp:1:
/usr/include/c++/4.7/bits/vector.tcc:92:7: note: void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {}; _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]
如何让这个工作?另外,为什么需要一个分配器(allocator)?
push_back
而不是emplace_back
时遇到了什么实际问题?你使用的编译器和标准库的名称和版本是什么? - Yakk - Adam Nevraumont