Rootcint crash with pointers to functions


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{

//typedef to save typing
typedef void (param::*Operation)(float &lhs);

// this is the array of function pointers
param::Operation *fOperation;
ClassDef(param, 1);


The cpp file simply contains and empty c’tor

Upon compilation, I get a seg fault from rootcint

[coganp@pcp177897pcs genetic]$ make
g++ -o out/param.o -c -Wall -g -fPIC -O3 -I…/common/include -Iinclude -I. -pthread -m64 -I/usr/local/include/root -I/usr/include/mysql -g -pipe -m64 src/param.cpp
rootcint -v -f out/root_dict.cpp -c -p -I…/common/include -Iinclude -I. include/param.h include/LinkDef.h
Segmentation fault

Note that if I put #ifndef CINT around the pointer to function stuff then rootcint does not seg fault

thanks in advance!


what about

[code]typedef void (*Operation)(float &lhs);

// this is the array of function pointers
Operation *fOperation;[/code]

Cheers, Axel.

Hi Axel,

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] = &param::f1;
fOperation[1] = &param::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] = &param::f1;
fOperation[0] = &f1;

but I get the same error



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
#ifndef CINT
Operation fOperation;
// CINT dummy declaration
Like this CINT sees the correct size of the object. This works because fOperation is an array of pointers to member function.

Cheers, Axel.

Hi Axel,

apologies for the slow reply - just back from vacation.

Your solution works perfectly. Thanks as always for the help