I am trying to implement an array of pointers to functions in a class which inherits from TObject. I get a segfault from rootcint when it tries to compile the root dictionary that is created. I am running root 5.22/00 on with gcc v 3.4.3
The header looks like this:
#ifndef PARAM #define PARAM
#include <TObject.h>
class param:public TObject{
public:
param();
//typedef to save typing
typedef void (param::*Operation)(float &lhs);
// this is the array of function pointers
param::Operation *fOperation;
ClassDef(param, 1);
};
thanks for the suggestion, that seems to half solve the problem. I am no longer getting a seg fault from rootcint, but now the C++ part is unhappy when I try to assign functions to my array of functions. So, in my constructor I would have
fOperation = new Operation[n];
fOperation[0] = ¶m::f1;
fOperation[1] = ¶m::f2;
note that f1 and f2 are member functions defined in the header of the form
void f1(float &);
void f2(float &);
When I do this, gcc gives the error :
cannot convert void (param::*)(float &)' tovoid (*)(float &)’ in assignment
I tried changing
fOperation[0] = ¶m::f1;
to
fOperation[0] = &f1;
OK, sorry - I didn’t realize that you really need pointers to member function (but actually should have guessed). CINT cannot parse that properly. Could you replace it with the following?
[code]//typedef to save typing
typedef void (param::*Operation)(float &lhs);
// this is the array of function pointers #ifndefCINT
Operation fOperation; #else
// CINT dummy declaration
void fOperation; #endif
[/code]
Like this CINT sees the correct size of the object. This works because fOperation is an array of pointers to member function.