当我尝试编译以下代码时,我遇到了错误


  在“结构result_of_make_control>”的实例中:
  
  54:53:需要替换为“模板类型名result_of_make_control :: type make_受控(类型名Stepper :: value_type,类型名Stepper :: value_type,const Stepper&)[with Stepper = runge_kutta_dopri5]”
  
  69:60:从这里需要
  
  49:54:错误:在“ struct get_controller>”中没有名为“ type”的类型
  
  typedef typename get_controller :: type类型;


class explicit_error_stepper_fsal_base
{
public:
typedef double state_type;
typedef double value_type;

};


template<class State>
class runge_kutta_dopri5
: public explicit_error_stepper_fsal_base
{

public :

    typedef explicit_error_stepper_fsal_base stepper_base_type;

    typedef typename stepper_base_type::value_type value_type;//#

    runge_kutta_dopri5(  )
    { }

};


template< class Stepper > struct get_controller { };



// default controller factory
template< class Stepper , class Controller >
struct controller_factory
{
    Controller operator()(
            typename Stepper::value_type abs_error ,
            typename Stepper::value_type rel_error ,
            const Stepper &stepper )
    {
        return Controller( abs_error , rel_error , stepper );
    }
};


template< class Stepper >
struct result_of_make_controlled
{
    typedef typename get_controller< Stepper >::type type;
};


template< class Stepper >
typename result_of_make_controlled< Stepper >::type make_controlled(
        typename Stepper::value_type abs_error ,
        typename Stepper::value_type rel_error ,
        const Stepper & stepper = Stepper() )
{
    typedef Stepper stepper_type;
    typedef typename result_of_make_controlled< stepper_type >::type controller_type;
    typedef controller_factory< stepper_type , controller_type > factory_type;
    factory_type factory;
    return factory( abs_error , rel_error , stepper );
}


typedef double state_type;
typedef runge_kutta_dopri5<state_type> stepper_type;
typedef decltype(make_controlled(1E-10,1E-10,stepper_type())) controlled_stepper_type;


int main()
{
    return 0;
}


我假设它需要在结构type中查找为get_controller的类型,而该结构为空并导致错误。我不明白的是,为什么在github boost library的原始源代码中,编译器方面没有问题?

最佳答案

相关的升压标题为特定步进器的get_controller提供部分专业化。您的代码不这样做。 For example

template< class State , class Value , class Deriv , class Time , class Algebra , class Operations , class Resize >
struct get_controller< runge_kutta_dopri5< State , Value , Deriv , Time , Algebra , Operations , Resize > >
{
    typedef runge_kutta_dopri5< State , Value , Deriv , Time , Algebra , Operations , Resize > stepper_type;
    typedef controlled_runge_kutta< stepper_type > type;
};

关于c++ - 通过替换template <class Stepper>所需,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28381863/

10-11 16:52