关于c ++:替换模板所需的< 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;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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库的原始源代码中,编译器方面没有问题?


相关的Boost头为特定步进器的get_controller提供部分专门化。你的代码不能做到这一点。例如:

1
2
3
4
5
6
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;
};