TF1 fitFunc(“fit”,MyFitFunc,…); /// This line doesn’t compile
histo->Fit(fitFunc,"");
}
==================================
I cannot find the correct syntax for the definition of the TF1 in order to use the defined function in other methods of my class.
What is the proper syntax for defining a TF1 object inside a class method that uses a user defined fit function that is another method in that same class?
Add a static member function to your class. this is the function that you will hook up to TF1. You’ll also want to add a static member data that is a pointer to the instance that you want to fit. In your static member function, you call the member function of your choice. So something like:
//inside class definition
static void staticFunction (...);
static MyClass *sm_ptr;
// source file
void
MyClass::staticFunction (...)
{
sm_ptr->MyFitFunc (...);
}
// use this
MyClass::sm_ptr = &myObject;
TF1 fit ("fit", MyClass::staticFunc);
I want to define the function within the class that it is used. In the case described by “moneta” this is still a function, contained inside a class, being used outside of that class.