gpt4 book ai didi

c++ - 需要替换模板

转载 作者:行者123 更新时间:2023-11-28 02:33:19 24 4
gpt4 key购买 nike

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

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 ,编译器方面没有问题吗?

最佳答案

相关的 boost header 为特定步进器的 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++ - 需要替换模板<class Stepper>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28381863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com