ROOT::Math::Functor does not work with class methods

I stumbled upon this while implementing a minimization following these instructions. In my case the function to minimize is a method of a class, since it needs the values of some class members for computation. When I try to compile my code I get this error:

/home/mori/software/install/ROOT_6.14.02/include/Math/Functor.h:120:21: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘((const ROOT::Math::FunctorHandler<ROOT::Math::Functor, double (TIC::GlobalAlignmentAlgo::*)(const double*)>*)this)->ROOT::Math::FunctorHandler<ROOT::Math::Functor, double (TIC::GlobalAlignmentAlgo::*)(const double*)>::fFunc (...)’, e.g. ‘(... ->* ((const ROOT::Math::FunctorHandler<ROOT::Math::Functor, double (TIC::GlobalAlignmentAlgo::*)(const double*)>*)this)->ROOT::Math::FunctorHandler<ROOT::Math::Functor, double (TIC::GlobalAlignmentAlgo::*)(const double*)>::fFunc) (...)’
       return fFunc(x);

This is a simple demonstrator code for better understanding (compile it with: g++ -I`root-config --incdir` `root-config --libs` testFunctor.cpp):

  #include "Math/Functor.h"
  class TestFunctor{
  public:
          double ToCall(float x){
                  return x;
          }
          void Caller(){
                  ROOT::Math::Functor functor(&TestFunctor::ToCall,1);
          }
};

int main(){
        TestFunctor f;

        return 0;
}

From what I understand the minimizer interface does not work when the function to minimize is a class method. Am I right or maybe I am overlooking something? Thanks.

May be @moneta has an idea.

Thanks, let’s see if Lorenzo has a clue. By the way, I circumvented the problem by using a lambda defined inside a method as the function to minimize; capturing all the object members allows for computing the function value, and Functor is happy with the lambda. But this is far from being a satisfactory solution, so let’s see if a proper one exists.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.