I have the following 2d vector / matrix Xand vector Yas shown below:
std::vector<double> Y;
unsigned int ctr=2;
std::vector<std::vector<double> >X(ctr,Y);
Now I want to create a transpose of X, i.e. Xtrans, so I declare it below
std::vector<std::vector<double> >Xtrans(Y,ctr);
but this gives me the following compilation error:
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> >]
How can I declare Xtrans correctly?
source
share