2014-01-24 1 views
2

Я использую VC++ 2010 Express с 64-битным компилятором, поставляемым с Windows SDK 7.1. Моей версией пакета обновления является boost_1_55_0.Ошибка C2309 в примере кода пакета boost odeint

Пример код форсированный пакета, odeint, найден here и следующим образом:

#include <iostream> 
#include <boost/numeric/odeint.hpp> 


using namespace std; 
using namespace boost::numeric::odeint; 


/* we solve the simple ODE x' = 3/(2t^2) + x/(2t) 
* with initial condition x(1) = 0. 
* Analytic solution is x(t) = sqrt(t) - 1/t 
*/ 

void rhs(const double x , double &dxdt , const double t) 
{ 
    dxdt = 3.0/(2.0*t*t) + x/(2.0*t); 
} 

void write_cout(const double &x , const double t) 
{ 
    cout << t << '\t' << x << endl; 
} 

// state_type = double 
typedef runge_kutta_dopri5<double> stepper_type; 

int main() 
{ 
    double x = 0.0;  
    integrate_adaptive(make_controlled(1E-12 , 1E-12 , stepper_type()) , 
         rhs , x , 1.0 , 10.0 , 0.1 , write_cout); 
} 

Однако это не компилируется. Сообщение об ошибке выглядит следующим образом:

1>------ Build started: Project: LearnBoost, Configuration: Debug x64 ------ 
1> test_odeint.cpp 
1>C:\boost_1_55_0\boost/format/alt_sstream_impl.hpp : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss 
1>C:\boost_1_55_0\boost/range/iterator.hpp(63): error C2039: 'type' : is not a member of 'boost::mpl::eval_if_c<C,F1,F2>' 
1>   with 
1>   [ 
1>    C=true, 
1>    F1=boost::range_const_iterator<double>, 
1>    F2=boost::range_mutable_iterator<const double> 
1>   ] 
1>   C:\boost_1_55_0\boost/numeric/odeint/algebra/range_algebra.hpp(52) : see reference to class template instantiation 'boost::range_iterator<C>' being compiled 
1>   with 
1>   [ 
1>    C=const double 
1>   ] 
1>   C:\boost_1_55_0\boost/numeric/odeint/stepper/controlled_runge_kutta.hpp(81) : see reference to function template instantiation 'void boost::numeric::odeint::range_algebra::for_each3<Err,const State,const Deriv,boost::numeric::odeint::default_operations::rel_error<Fac1>>(S1 &,S2 &,S3 &,Op)' being compiled 
1>   with 
1>   [ 
1>    Err=double, 
1>    State=double, 
1>    Deriv=double, 
1>    Fac1=double, 
1>    S1=double, 
1>    S2=double, 
1>    S3=double, 
1>    Op=boost::numeric::odeint::default_operations::rel_error<double> 
1>   ] 
1>   C:\boost_1_55_0\boost/numeric/odeint/stepper/controlled_runge_kutta.hpp(710) : see reference to function template instantiation 'double boost::numeric::odeint::default_error_checker<Value,Algebra,Operations>::error<StateIn,DerivIn,V,double>(boost::numeric::odeint::range_algebra &,const State &,const Deriv &,Err &,Time) const' being compiled 
1>   with 
1>   [ 
1>    Value=double, 
1>    Algebra=boost::numeric::odeint::range_algebra, 
1>    Operations=boost::numeric::odeint::default_operations, 
1>    StateIn=double, 
1>    DerivIn=double, 
1>    V=double, 
1>    State=double, 
1>    Deriv=double, 
1>    Err=double, 
1>    Time=double 
1>   ] 
1>   C:\boost_1_55_0\boost/numeric/odeint/stepper/controlled_runge_kutta.hpp(660) : see reference to function template instantiation 'boost::numeric::odeint::controlled_step_result boost::numeric::odeint::controlled_runge_kutta<ErrorStepper>::try_step<void(__cdecl *)(double,double &,double),StateInOut,DerivInOut,V,V>(System,const StateIn &,const DerivIn &,double &,StateOut &,DerivOut &,double &)' being compiled 
1>   with 
1>   [ 
1>    ErrorStepper=boost::numeric::odeint::runge_kutta_dopri5<double>, 
1>    StateInOut=double, 
1>    DerivInOut=double, 
1>    V=double, 
1>    System=void (__cdecl *)(double,double &,double), 
1>    StateIn=double, 
1>    DerivIn=double, 
1>    StateOut=double, 
1>    DerivOut=double 
1>   ] 
1>   C:\boost_1_55_0\boost/numeric/odeint/stepper/controlled_runge_kutta.hpp(853) : see reference to function template instantiation 'boost::numeric::odeint::controlled_step_result boost::numeric::odeint::controlled_runge_kutta<ErrorStepper>::try_step<void(__cdecl *)(double,double &,double),StateInOut,V>(System,StateInOut &,DerivInOut &,double &,double &)' being compiled 
1>   with 
1>   [ 
1>    ErrorStepper=boost::numeric::odeint::runge_kutta_dopri5<double>, 
1>    StateInOut=double, 
1>    V=double, 
1>    System=void (__cdecl *)(double,double &,double), 
1>    DerivInOut=double 
1>   ] 
1>   C:\boost_1_55_0\boost/numeric/odeint/stepper/controlled_runge_kutta.hpp(561) : see reference to function template instantiation 'boost::numeric::odeint::controlled_step_result boost::numeric::odeint::controlled_runge_kutta<ErrorStepper>::try_step_v1<void(__cdecl *)(double,double &,double),StateInOut>(System,StateInOut &,double &,double &)' being compiled 
1>   with 
1>   [ 
1>    ErrorStepper=boost::numeric::odeint::runge_kutta_dopri5<double>, 
1>    StateInOut=double, 
1>    System=void (__cdecl *)(double,double &,double) 
1>   ] 
1>   C:\boost_1_55_0\boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp(98) : see reference to function template instantiation 'boost::numeric::odeint::controlled_step_result boost::numeric::odeint::controlled_runge_kutta<ErrorStepper>::try_step<void(__cdecl *)(double,double &,double),State>(System,StateInOut &,double &,double &)' being compiled 
1>   with 
1>   [ 
1>    ErrorStepper=boost::numeric::odeint::runge_kutta_dopri5<double>, 
1>    State=double, 
1>    System=void (__cdecl *)(double,double &,double), 
1>    StateInOut=double 
1>   ] 
1>   C:\boost_1_55_0\boost/numeric/odeint/integrate/integrate_adaptive.hpp(44) : see reference to function template instantiation 'size_t boost::numeric::odeint::detail::integrate_adaptive<Stepper,void(__cdecl *)(double,double &,double),State,Time,void(__cdecl *)(const double &,double)>(Stepper,System,State &,Time &,Time,Time &,Observer,boost::numeric::odeint::controlled_stepper_tag)' being compiled 
1>   with 
1>   [ 
1>    Stepper=boost::numeric::odeint::controlled_runge_kutta<boost::numeric::odeint::runge_kutta_dopri5<double>>, 
1>    State=double, 
1>    Time=double, 
1>    System=void (__cdecl *)(double,double &,double), 
1>    Observer=void (__cdecl *)(const double &,double) 
1>   ] 
1>   test_odeint.cpp(31) : see reference to function template instantiation 'size_t boost::numeric::odeint::integrate_adaptive<boost::numeric::odeint::controlled_runge_kutta<ErrorStepper>,void(__cdecl *)(double,double &,double),double,double,void(__cdecl *)(const double &,double)>(Stepper,System,State &,Time,Time,Time,Observer)' being compiled 
1>   with 
1>   [ 
1>    ErrorStepper=boost::numeric::odeint::runge_kutta_dopri5<double>, 
1>    Stepper=boost::numeric::odeint::controlled_runge_kutta<boost::numeric::odeint::runge_kutta_dopri5<double>>, 
1>    System=void (__cdecl *)(double,double &,double), 
1>    State=double, 
1>    Time=double, 
1>    Observer=void (__cdecl *)(const double &,double) 
1>   ] 
1>C:\boost_1_55_0\boost/range/iterator.hpp(63): error C2039: 'type' : is not a member of 'boost::mpl::eval_if_c<C,F1,F2>' 
1>   with 
1>   [ 
1>    C=false, 
1>    F1=boost::range_const_iterator<double>, 
1>    F2=boost::range_mutable_iterator<double> 
1>   ] 
1>   C:\boost_1_55_0\boost/numeric/odeint/algebra/range_algebra.hpp(52) : see reference to class template instantiation 'boost::range_iterator<C>' being compiled 
1>   with 
1>   [ 
1>    C=double 
1>   ] 
1>C:\boost_1_55_0\boost/numeric/odeint/algebra/range_algebra.hpp(52): error C2664: 'boost::numeric::odeint::detail::for_each3' : cannot convert parameter 1 from 'boost::type' to 'boost::type' 
1>   The target type has no constructors 
1>C:\boost_1_55_0\boost/numeric/odeint/algebra/range_algebra.hpp(130): error C2664: 'boost::numeric::odeint::detail::reduce' : cannot convert parameter 1 from 'boost::type' to 'boost::type' 
1>   The target type has no constructors 
1>   C:\boost_1_55_0\boost/numeric/odeint/stepper/controlled_runge_kutta.hpp(84) : see reference to function template instantiation 'Value boost::numeric::odeint::range_algebra::reduce<double,Err,boost::numeric::odeint::default_operations::maximum<Value>>(const S &,Red,Value)' being compiled 
1>   with 
1>   [ 
1>    Value=double, 
1>    Err=double, 
1>    S=double, 
1>    Red=boost::numeric::odeint::default_operations::maximum<double> 
1>   ] 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

ответ

2

Это сработало. Я использую эту строку:

// state_type = value_type = deriv_type = time_type = double 
typedef runge_kutta_dopri5< double , double , double , double , vector_space_algebra , default_operations , never_resizer > stepper_type; 

заменить эту строку:

// state_type = double 
typedef runge_kutta_dopri5<double> stepper_type; 

И это теперь исправлено. В принципе, пример устарел, а в папке примера кода есть правильный код.

+0

Да, существует несоответствие версии между boost и версией odeint github. Он будет зафиксирован с помощью boost-1.56. Тем не менее код на веб-странице повышения должен быть правильным. – headmyshoulder

+0

@headmyshoulder Спасибо! Да, вы правы, я думаю, что у меня есть неправильный код, потому что я пошел на веб-сайт odeint, а не в boost. В любом случае, счастлив, что проблема решена и, надеюсь, кто-то другой, имеющий ту же путаницу, может воспользоваться этим вопросом! –