Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

Hi, I have a template function

C++
template<class /> double RombergIntegral(const double& a, const double& b,const T& f, const int& order)

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

C++
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?

Posted
Updated 19-Nov-09 11:14am
v2

1 solution

You may try

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);
  }
};
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900