Turn C++ method into TF1?

Hello, I’ve been staring at my code for some time, and I am trying to turn a function into a TF1 class.

This is the method:

double yukawa(double mu){ double temp=0.0; temp=pow((2./(3.-2*mu)),2); return temp; }

I try to force it to be TF1:

I get a nice message :

qm3.cxx:160:44: error: call of overloaded ‘TF1(const char [2], double (&)(double), int, int)’ is ambiguous TF1 *Yukawa_Plot= new TF1("Y",yukawa,-1,1); ^ qm3.cxx:160:44: note: candidates are: In file included from qm3.cxx:16:0: /home/SJL/ROOT/include/TF1.h:217:4: note: TF1::TF1(const char*, ROOT::Math::ParamFunctor, Double_t, Double_t, Int_t, Int_t) <near match> TF1(const char *name, ROOT::Math::ParamFunctor f, Double_t xmin = 0, Double_t xmax = 1, Int_t npar = 0,Int_t ndim = 1); ^ /home/SJL/ROOT/include/TF1.h:217:4: note: no known conversion for argument 2 from ‘double(double)’ to ‘ROOT::Math::ParamFunctor’ /home/SJL/ROOT/include/TF1.h:213:4: note: TF1::TF1(const char*, Double_t (*)(const Double_t*, const Double_t*), Double_t, Double_t, Int_t, Int_t) <near match> TF1(const char *name, Double_t (*fcn)(const Double_t *, const Double_t *), Double_t xmin=0, Double_t xmax=1, Int_t npar=0,Int_t ndim = 1); ^ /home/SJL/ROOT/include/TF1.h:213:4: note: no known conversion for argument 2 from ‘double(double)’ to ‘Double_t (*)(const Double_t*, const Double_t*) {aka double (*)(const double*, const double*)}’ In file included from qm3.cxx:16:0: /home/SJL/ROOT/include/TF1.h:212:4: note: TF1::TF1(const char*, Double_t (*)(Double_t*, Double_t*), Double_t, Double_t, Int_t, Int_t) <near match> TF1(const char *name, Double_t (*fcn)(Double_t *, Double_t *), Double_t xmin=0, Double_t xmax=1, Int_t npar=0, Int_t ndim = 1); ^ /home/SJL/ROOT/include/TF1.h:212:4: note: no known conversion for argument 2 from ‘double(double)’ to ‘Double_t (*)(Double_t*, Double_t*) {aka double (*)(double*, double*)}’ Compilation failed If 'qm3' is not a typo you can use command-not-found to lookup the package that contains it, like this: cnf qm3

It’s killing me, because I’m following
https://root.cern.ch/doc/master/classTF1.html

1.Case3

Try: TF1 *Yukawa_Plot= new TF1("Y", "yukawa(x)", -1.0, 1.0); or try: #include <cmath> double yukawa(const double *x, const double*p) { double mu = x[0]; double temp=0.0; temp = std::pow((2./(3.-2*mu)),2); return temp; } with: TF1 *Yukawa_Plot= new TF1("Y", yukawa, -1.0, 1.0, 0);

I’m learning that method only really works in a Macro, but not in compiled format.

Actually, you should be able to use both methods in compiled code (in the first case, the “yukawa” function needs to be known to the interpreter, so that it can evaluate “yukawa(x)”).