Hi,
I got an error while compiling the following code:
#include <Fit/Fitter.h>
#include <TF1.h>
#include <print>
auto main() -> int
{
auto fitter = ROOT::Fit::Fitter{};
auto fitted_function = TF1{ "linear",
[](const double* variables, const double* parameters) -> double
{
auto x_val = variables[0];
return x_val * parameters[0] + parameters[1];
},
-10,
10,
3,
1 };
return 0;
}
The error message from clang is:
[3/4] Building CXX object CMakeFiles/main.dir/main.cpp.o
FAILED: CMakeFiles/main.dir/main.cpp.o
/usr/sbin/clang++ -isystem /opt/FairSoft/include/root -std=gnu++23 -MD -MT CMakeFiles/main.dir/main.cpp.o -MF CMakeFiles/main.dir/main.cpp.o.d @CMakeFiles/main.dir/main.cpp.o.modmap -o CMakeFiles/main.dir/main.cpp.o -c /u/yanwang/software/neulandproject/tutorials/root_fitter/main.cpp
/u/yanwang/software/neulandproject/tutorials/root_fitter/main.cpp:10:28: error: call to constructor of 'TF1' is ambiguous
10 | auto fitted_function = TF1{ "linear",
| ^ ~~~~~~~~~~~
11 | [](const double* variables, const double* parameters) -> double
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 | {
| ~
13 | auto x_val = variables[0];
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
14 | return x_val * parameters[0] + parameters[1];
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 | },
| ~~
16 | -10,
| ~~~~
17 | 10,
| ~~~
18 | 3,
| ~~
19 | 1 };
| ~~~
/opt/FairSoft/include/root/TF1.h:425:4: note: candidate constructor [with PtrObj = (lambda at /u/yanwang/software/neulandproject/tutorials/root_fitter/main.cpp:11:33), MemFn = int]
425 | TF1(const char *name, const PtrObj &p, MemFn memFn, Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim = 1, EAddToList addToGlobList = EAddToList::kDefault) :
| ^
/opt/FairSoft/include/root/TF1.h:400:4: note: candidate constructor [with Func = (lambda at /u/yanwang/software/neulandproject/tutorials/root_fitter/main.cpp:11:33)]
400 | TF1(const char *name, Func f, Double_t xmin, Double_t xmax, Int_t npar, Int_t ndim = 1, EAddToList addToGlobList = EAddToList::kDefault) :
| ^
/opt/FairSoft/include/root/TF1.h:357:4: note: candidate constructor
357 | 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, EAddToList addToGlobList = EAddToList::kDefault);
| ^
1 error generated.
ninja: build stopped: subcommand failed.
Thanks for your attention
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.36.04
Platform: fedora 42
Compiler: clang 20.1.8