0
votes

A colleague has provided me with a package of c++ code based on some Celestrak satellite code http://celestrak.com/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::allocator >]': 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::allocator >; std::vector<_Tp, _Alloc>::allocator_type = std::allocator >]' stl_vector.h:1166:59: error: no matching function for call to 'std::vector >::_M_fill_initialize(std::vector >::size_type, int&)' _M_fill_initialize(static_cast(__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?

1
"won't compile on my system yet does for the colleague". Do you use different compilers? - Zeta
Did you try with -std=c++11? - Simón Oroño
It doesn't look legal to me. The second parameter needs to be a value type which, in this case, is a std::vector<double>. Try substituting it for this: std::vector< std::vector<double> > nut(3, std::vector<double>(3));. It may be your friend has an implementation with a non-standard constructor? REFERENCE: en.cppreference.com/w/cpp/container/vector/vector - Galik
So, I'm assuming the software comes with no Makefile or build instructions? - user3920237
The code is including <vector.h> which is not standard C++. There's your problem. - user3920237

1 Answers

0
votes

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.