NumericalMinimization in a class


The NumericalMinimization.C code in the fit tutorial section is a nice example. What I would like to do is use the tools from this example in a larger project. So, as a first test I added a main function to create the attached “NumericalMinimization.cpp”. This compiled fine for me with g++. Now, what I really want to do is implement this in a class. So, I further modified the example, resulting in the attached “NM2.cpp”. The problem is that this fails when compiling, giving the error message:

g++ -o NM2 -O3 -Wall -pthread -m64 -I/usr/local/root/include NM2.cpp -L/usr/local/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -L/usr/local/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lGui -pthread -lm -ldl -rdynamic -lMathMore
/usr/local/root/include/Math/Functor.h: In member function ‘double ROOT::Math::FunctorHandler<ParentFunctor, Func>::DoEval(const double*) const [with ParentFunctor = ROOT::Math::Functor, Func = double (Test::)(const double)]’:
NM2.cpp:106: instantiated from here
/usr/local/root/include/Math/Functor.h:86: error: must use ‘.’ or '->’ to call pointer-to-member function in ‘((const ROOT::Math::FunctorHandler<ROOT::Math::Functor, double (Test::)(const double)>)this)->ROOT::Math::FunctorHandler<ROOT::Math::Functor, double (Test::)(const double*)>::fFunc (…)’

It is very likely that I’m missing a key idea in how the inheritance is implemented for Functor, and hopefully the solution is simple. Help with fixing my “NM2.cpp” code to allow using the Functor and Minimizer Factory within a class will be greatly appreciated.

NM2.cpp (2.57 KB)
NumericalMinimization.cpp (2.48 KB)


The Functor class can be used to wrap also a member function with the right signature
(i.e. double F(const double *), but in this case you need to use a different constructor, the one who takes as input both a class object pointer and the member function pointer.
In your example the correct statement is:

ROOT::Math::Functor f(this, &Test::RosenBrock,2); 

Best Regards