Dear all,
I have a class with a TF1 as member. This TF1 should point to a member function of this class, something like
class Testclass {
public:
Testclass() {
function = new TF1("spectrum",this,&Testclass::member,1,10,0);
}
TF1 * function;
private:
double member(double *x, double *p) {
return x[0];
}
};
This works fine as long as I just create one object of this class. Creating more than one object leads to a segfault (see attachment for a running example).
One solution I have found is to let TF1 point to an external wrapper class which itself holds a pointer to the particular “Testclass” object to which the TF1 belongs (and then calls pointer_to_testclass_object->member()). Moreover, the name of the TF1 apparently must be different for every instance of Testclass.
However, all this seems rather clumsy to me. What would be the correct way of doing something like this?
Thanks for your help,
Jens
testmacro.cxx (357 Bytes)