#include <initializer_list>
#include <vector>
class Foo {
std::vector<std::vector<int> > data;
public:
Foo(std::initializer_list<std::initializer_list<int> > & data) : data(data) {}
};
int main(){
Foo f {{1,2},{3,3}};
return 0;
}
,編譯器抱怨:
initalizer_list_test.cpp: In constructor ‘Foo::Foo(std::initializer_list<std::initializer_list<int> >&)’:
initalizer_list_test.cpp:11:79: error: no matching function for call to ‘std::vector<std::vector<int> >::vector(std::initializer_list<std::initializer_list<int> >&)’
Foo(std::initializer_list<std::initializer_list<int> > & data) : data(data) {}
^
initalizer_list_test.cpp:11:79: note: candidates are:
In file included from /usr/include/c++/4.8.2/vector:64:0,
from initalizer_list_test.cpp:2:
/usr/include/c++/4.8.2/bits/stl_vector.h:392:9: note: template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&)
vector(_InputIterator __first, _InputIterator __last,
^
/usr/include/c++/4.8.2/bits/stl_vector.h:392:9: note: template argument deduction/substitution failed:
initalizer_list_test.cpp:11:79: note: candidate expects 3 arguments, 1 provided
Foo(std::initializer_list<std::initializer_list<int> > & data) : data(data) {}
如何讓它正常工作?
也不會轉回去的std :: initializer_list >> do? –
JonPall