I’m rewritting some c code into a C++ class for use with ROOT and have run into a problem. I’ve made a short test class which has two member functions in addition to ctor and dtor. One of the functions expects to take a member function pointer.
The code compiles but I can not compile the source code generated by rootcint. When I try to compile I get an error stating that I’m asking for a function pointer of calling convertion __thiscall but sending __cdecl.
May be I’m wrong and CINT experts know how to fix this, but
IMHO, Cint cannot work correctly with such a code - it generates some nightmarish illegal conversions like this:
Even if you try manually fix this - it’s impossible - pointer-to-member is not a usuall pointer and cannot be cast to/from integer.
May be, you can skip class dictionary generation? Or you can use pointer-to-member as a data-member, but do not pass as a member-function parameter - use it in a function and assign value to it somewhere else.
class classmf
{
public:
int (classmf::*memPtr)(int);
void fun()
{
(*this.*memPtr)(10);
}
int fun1(int);
int fun2(int);
.....
};
int main()
{
classmf obj;
//////
obj.memPtr = &classmf::fun1;
obj.fun();
}
Thanks for the replies. I looked through TFormulaPrimitive but didn’t understand how I could use it for my situation.
I decided to give up and switch over to static functions and that worked. When things slow down, I’ll try the member function approach again and post my solution.