I have a simple test program. It doesn't work. I want to know what is the
reason and how to
fix it. Maybe I should use template function to do it. But I don't know how.
Here is the simple program. Strange enough that the problem never happens in
C languge,
i.e., in the program, if I call "foo2", it works fine. Why "foo1" doesn't
work?
Thanks for your answers.
////////////////////////////////////////////////////////////////////////////
/
file://main.cpp
////////////////////////////////////////////////////////////////////////////
/
#include <stdio.h>
#include <stdlib.h>
#include "Funct.h"
void main()
{
double s;
Funct funct;
s = funct.drive();
printf("Result= %lf", s);
}
////////////////////////////////////////////////////////////////////////////
/
file://Funct.h
////////////////////////////////////////////////////////////////////////////
/
double foo2(double t);
class Funct
{
double Integrate(double(*func)(double), double a, double b);
double foo1(double t);
public:
double drive();
};
////////////////////////////////////////////////////////////////////////////
/
file://Funct.cpp
////////////////////////////////////////////////////////////////////////////
/
#include "Funct.h"
double Funct::Integrate(double (*func)(double), double a, double b)
{
double c = a+b;
return func(c);
}
double Funct::foo1(double t)
{
return t*t;
}
double Funct::drive()
{
double t = Integrate(foo1, 2, 3);
// double t = Integrate(foo2, 2, 3);
return t;
}
double foo2(double t)
{
return t*t;
}
**************************************