本文介绍了在类中使用模板函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有模板功能
template<class /> double RombergIntegral(const double& a, const double& b,const T& f, const int& order)
我想在[a,b]中计算一个函数的积分,我想在一个非模板类中使用它来集成类成员函数,例如
for calculating the integral of a function in [a,b] which I want to use inside a non-templated class for integrating a class member function like
double MyModel::function(double t)
尤其是我想在另一个成员函数中执行此操作,即我想编写类似的内容
In particular I would like to do this inside another member function, i.e I want to write something like
double MyModel::integral_function(double t) {
return RombergIntegral<double(double)>(0.0,t,&MyModel::function,5)
}
这不起作用.最好的方法是什么?
which doesn''t work. What is the best way to do this?
推荐答案
template <typename T>
double RombergIntegral(const double& a, const double& b, static T (*f)(T), const int& order)
{
//stuff here...
}
class MyModel
{
public:
static double function(double t)
{
// stuff here...
}
double integral_function(double t)
{
return RombergIntegral < double > (0.0, t, &MyModel::function, 5);
}
};
这篇关于在类中使用模板函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!