我有以下成员函数:
void GClass::InitFunctions()
{ // Initialize arrays of pointers to functions.
ComputeIntLen[0] = &ComputeILS;
ComputeIntLen[1] = &ComputeILE;
ComputeIntLen[2] = &ComputeILI;
PostStep[0] = &PSS;
PostStep[1] = &PSE;
PostStep[2] = Ψ
gRotation = new Rotation();
}
GClass 显然包含了所有相关成员 -:
void ComputeILE(Int_t, Int_t *, Double_t *);
void ComputeILI(Int_t, Int_t *, Double_t *);
void PSS(Int_t , Int_t *, Int_t &, Int_t*);
void PSE(Int_t, Int_t *, Int_t &, Int_t*);
void PSI(Int_t , Int_t *, Int_t &, Int_t*);
ComputeIntLenFunc ComputeIntLen[gNproc];
PostStepFunc PostStep[gNproc];
... //other members
}
其中gNproc是全局常量int,ComputeIntLenFunc和PostStepFunc是如下所示的typedef:
typedef void (*ComputeIntLenFunc)(Int_t ntracks, Int_t *trackin, Double_t *lengths);
typedef void (*PostStepFunc)(Int_t ntracks, Int_t *trackin, Int_t &nout, Int_t* trackout);
当我编译它时,gcc报错:"ISO C++禁止取非限定或带括号的非静态成员函数的地址以形成指向成员函数的指针。请使用'&GClass :: ComputeIntLenScattering' " 当我在InitFunctions()中将FunctionNames替换为GClass :: FunctionNames时,我得到了"无法将 'void (GClass ::*)(Int_t,Int_t *,Double_t *)'转换为'void (*)(Int_t,Int_t *,Double_t *)'的分配" 请帮助我。这是C ++的哪个主题?
GClass something;
,这是否意味着something
_是_一个类?也许GObject
会稍微好一点(尽管仍然非常通用)。 - Andre