manoj
March 27, 2008, 7:21pm
1
Hi,
Why is this simple code not compiling?
test.h
#ifndef __test__
#define __test__
#include "TF1.h"
class test
{
private:
TF1 *fFunc;
public:
test();
~test();
double FitFunc(double *x, double *par); // a fit function
};
#endif
test.cxx
#include "test.h"
test::test()
{
fFunc = new TF1("FitFunc", FitFunc, 0.0, 1.0, 1); // fit function
}
double test::FitFunc(double *x, double *par)
{
return par[0]*x[0];
}
errors:
/home/test.cxx:5: error: no matching function for call to ‘TF1::TF1(const char [8], , double, double, int)’
Thanks
test.h[code]#ifndef test
#define test
class TF1;
class test
{
private:
TF1 *fFunc;
public:
test();
~test() {;};
};
#endif [/code]test.cxx[code]#include “test.h”
#include <TF1.h>
double FitFunc(double *x, double *par);
test::test()
{
fFunc = new TF1(“FitFunc”, FitFunc, 0.0, 1.0, 1); // fit function
}
double FitFunc(double *x, double *par)
{
return par[0]*x[0];
}
[/code]Jan
brun
March 27, 2008, 7:53pm
3
do
test.h
[code]#ifndef test
#define test
#include “TF1.h”
class test
{
private:
TF1 *fFunc;
public:
test();
~test();
};
#endif [/code]
test.cxx
[code]#include “test.h”
#include <TF1.h>
double FitFunc(double *x, double *par)
{
return par[0]*x[0];
}
test::test()
{
fFunc = new TF1(“FitFunc”, FitFunc, 0.0, 1.0, 1); // fit function
}
[/code]
and see doc of TF1
Rene
manoj
March 27, 2008, 8:21pm
4
Thanks a lot for your quick reply. I tried both ways. Both codes did not compile.
Also, it will be very helpful if it is possible to define the FitFunc(double *x, double *par) inside the class “test” as its member function. Your help will be greatly appreciated.
Thanks.
brun
March 27, 2008, 10:14pm
5
my code compiles if you add (this should be obvious!) the dummy destructor.
see the doc of TF1 for the remaining part of your question.
Rene