Functor Issues when Compiling

Hi, I had some code which worked using CINT and when loading with gROOT->ProcessLine(“mycode.C+”). I am trying to compile it externally using clang++ (or g++), but I get errors about the ROOT::Math::Functor constructors.

Here is my error message:

clang++-mp-3.2 -std=c++11 -Wno-c++11-extensions -o ana do_ana.C -I`root-config --incdir` `root-config --glibs` In file included from do_ana.C:12: ./JFTrackFit.C:294:23: error: no matching constructor for initialization of 'ROOT::Math::Functor' ROOT::Math::Functor ftor(&jftf,2,"JFTrackFit"); ^ ~~~~~~~~~~~~~~~~~~~~ /opt/local/include/root/Math/Functor.h:358:4: note: candidate constructor [with PtrObj = JFTrackFit *, MemFn = int] not viable: no known conversion from 'const char [11]' to 'unsigned int' for 3rd argument Functor(const PtrObj& p, MemFn memFn, unsigned int dim ) ^ /opt/local/include/root/Math/Functor.h:369:4: note: candidate constructor template not viable: requires 2 arguments, but 3 were provided Functor( const Func & f, unsigned int dim ) : ^ /opt/local/include/root/Math/Functor.h:351:4: note: candidate constructor not viable: requires 0 arguments, but 3 were provided Functor () : fImpl(0) {} ^ /opt/local/include/root/Math/Functor.h:389:4: note: candidate constructor not viable: requires single argument 'rhs', but 3 arguments were provided Functor(const Functor & rhs) : ^ 1 error generated.

Indeed it seems (when reading the .h file) that the constructor that I am using is protected by an #if defined(CINT) block. Online it is here: http://root.cern.ch/root/html/src/ROOT__Math__Functor.h.html#374

Unfortunately the other constructors at http://root.cern.ch/root/html/ROOT__Math__Functor.html are not clear. What is a MemFn object? In fact, the constructors in the summary list do not match those listed below, and there is no mention that one of the constructors only works in CINT.

What is the workaround? Thanks for any help.

Jean-François

The documentation didn’t help, but I tried playing around with std::mem_fun (to no avail) and eventually one of my guesses ended up satisfying the compiler.

It turns out that ROOT::Math::Functor (when not in CINT) wants an actual functor as an argument, not the address of a functor. So I have to do

ROOT::Math::Functor(jftf,2)
instead of

and now it works (or goes on to the next error…)

Jean-François