Function calling

Hi Rooters,

I have the following trouble:

  • In a file (main.cxx), I have the following main block
int main(int argc, char *argv[])
{
  // Load the function
  gROOT->LoadMacro("Macros.C");
  KLASS * myClass = new KLASS(FUNCTION);
}

The prototype for KLASS is KLASS(void *).

  • FUNCTION is a function defined in Macros.C:
    void FUNCTION(double *x, double *y)
    {
    y[0] = [[ something like function(x[0]) ]];
    }

This function is used later to be the void * _fMethod in a class which inherits from ROOT::Math::IBaseFunctionMultiDim

1°) The content of the main block is the reproduction of another macro, which runs well, the function FUNCTION is found…but not here (Of course, compilation fails, FUNCTION is not recognized).
2°) Declare FUNCTION in Main.cxx doesn’t solve it, because it is a (void *) (double, double) , the prototype waiting for a void *. Of course, I can cast FUNCTION as a void *.

But after, looking at my outputs, it seems that the calling of FUNCTION didn’t go well.

I’d prefer to use the LoadMacro method because it seems to consider FUNCTION directly as a void * but apparently it is not possible?

Cédric

Hi,

You seemed to be tried to pass an interpreted function to a compiled function. This is currently not trivial, you will need to look at the implementation of the class TF1 for details (and/or use TF1 as an intermediate).

Cheers,
Philippe.

ok, thanks Philippe, i’ll try this!

Cédric