user2415058
user2415058

Reputation: 23

declaring / compiling 2d vector of vectors

A colleague has provided me with a package of c++ code based on some Celestrak satellite code https://celestrak.org/software/vallado/cpp.zip.

In several places the code, i.e coordfk5.cpp declares vectors of vectors like

std::vector< std::vector<double> > prec, nut(3,3), st, stdot, pm, pmp

The nut(3,3) and similar declarations won't compile on my system yet does for the colleague on his and presumably others who have downloaded the original package.

stl_vector.h: In instantiation of 'void std::vector<_Tp, _Alloc>::_M_initialize_dispatch(_Integer, _Integer, std::__true_type) [with _Integer = int; _Tp = std::vector; _Alloc = std::allocatorstd::vector<double >]': stl_vector.h:404:55: required from 'std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = int; _Tp = std::vector; _Alloc = std::allocatorstd::vector<double >; std::vector<_Tp, _Alloc>::allocator_type = std::allocatorstd::vector<double >]' stl_vector.h:1166:59: error: no matching function for call to 'std::vectorstd::vector<double >::_M_fill_initialize(std::vectorstd::vector<double >::size_type, int&)' _M_fill_initialize(static_cast<size_type>(__n), __value);

I'm on gcc version 4.8.1, the colleague is on 4.6.3. I've tried adding -std=c++98 etc options to no avail.

I can get the code to compile by changing to eg

 nut(3,std::vector<double>(3))

but not sure if this is right as the code then seg faults.

So two questions,

Is it possible with some options/switches to compile the code as is?

If not any idea how these vectors should be declared and set-up?

Upvotes: 0

Views: 333

Answers (1)

M.M
M.M

Reputation: 141544

The nut(3,3) attempts to use 3 as initializer for the inner std::vector<int>.

However, std::vector has an explicit constructor which is why it doesn't compile. As you have found, explicit constructors have to have the type explicitly written, with nut(3, std::vector<int>(3)).

Some older compilers came with a vector that didn't mark the constructor as explicit which would explain your colleagues' observations.

Upvotes: 0

Related Questions