P
Protoman
Can you have a function pointer as a data member? Like:
template <class T>
class Integrate
{
public:
Integrate(long double& (T* f)(T& x)):fn(f){}
long double& operator()(T& lowLimit, T& upLimit) const;
private:
long double& (T* fn)(T& x);
};
long double& Integrate:perator()(T& lowLimit, T& upLimit) const
{
long double sum = 0.0;
T x;
// Evaluate integral{a,b} f(x) dx
for (long long n=0;n<=100;n++)
{
x = (n/100.0)*(b-a)+a;
sum +=(*f)(x)*(b-a)/101.0;
}
return sum;
}
Thanks!!!
template <class T>
class Integrate
{
public:
Integrate(long double& (T* f)(T& x)):fn(f){}
long double& operator()(T& lowLimit, T& upLimit) const;
private:
long double& (T* fn)(T& x);
};
long double& Integrate:perator()(T& lowLimit, T& upLimit) const
{
long double sum = 0.0;
T x;
// Evaluate integral{a,b} f(x) dx
for (long long n=0;n<=100;n++)
{
x = (n/100.0)*(b-a)+a;
sum +=(*f)(x)*(b-a)/101.0;
}
return sum;
}
Thanks!!!