需要替换模板<class Stepper>

required by substitution of template<class Stepper>

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

In instantiation of ‘struct result_of_make_controlled >’:

54:53: required by substitution of ‘template typename result_of_make_controlled::type make_controlled(typename Stepper::value_type, typename Stepper::value_type, const Stepper&) [with Stepper = runge_kutta_dopri5]’

69:60: required from here

49:54: error: no type named ‘type’ in ‘struct get_controller >’

typedef typename get_controller< Stepper >::type 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;
}

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

相关提升 headers 为特定步进器提供 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;
};