我有以下二维向量/矩阵X
和Y
如下向量:
std::vector<double> Y;
unsigned int ctr=2;
std::vector<std::vector<double> >X(ctr,Y);
我现在想创建 X 的转置,即 Xtrans,所以声明如下
std::vector<std::vector<double> >Xtrans(Y,ctr);
但它给了我以下编译错误:
test.cpp:128:58: error: no matching function for call to ‘std::vector<std::vector<double> >::vector(std::vector<double>&, unsigned int&)’
/usr/include/c++/4.5/bits/stl_vector.h:241:7: note: candidates are: std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::vector<double>, _Alloc = std::allocator<std::vector<double> >, std::vector<_Tp, _Alloc> = std::vector<std::vector<double> >]
/usr/include/c++/4.5/bits/stl_vector.h:227:7: note: std::vector<_Tp, _Alloc>::vector(std::vector::size_type, const value_type&, const allocator_type&) [with _Tp = std::vector<double>, _Alloc = std::allocator<std::vector<double> >, std::vector::size_type = unsigned int, value_type = std::vector<double>, allocator_type = std::allocator<std::vector<double> >]
/usr/include/c++/4.5/bits/stl_vector.h:215:7: note: std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = std::vector<double>, _Alloc = std::allocator<std::vector<double> >, allocator_type = std::allocator<std::vector<double> >]
/usr/include/c++/4.5/bits/stl_vector.h:207:7: note: std::vector<_Tp, _Alloc>::vector() [with _Tp = std::vector<double>, _Alloc = std::allocator<std::vector<double> >]
如何正确声明 Xtrans?