Verdi March wrote: One of the C function
takes a pointer to function as an argument: cfunction(int (*callback)(int, *char[]));
The wrapper uses a pure virtual function: class Process { public: virtual int run(int i, *char[]) = 0; };
Problem is, how to "convert" run to "callback"? I've tried cfunction(&Process::run), but g++ keeps complaining:
The basic problem here AFAIK is that C++ treats pointers to functions and pointers to member functions differently. As it stands &Process::run will return a pointer to member function. This cannot be used in place of a pointer to a function. Hence the compile error. If I recall correctly, it would be OK if Process::run were static. But a function can't be both virtual and static. STL uses member function adapters to allow you to call member functions as if they were not member functions, but, I think this relies on STL functions being overloaded to allow either functors or function pointers as arguments. Since C can't use functors, I think this method is not possible here. It would try a different method. I suspect that you could do something here. Maybe give each Process subclass a static function called run, give Process a static function pointer, initialised to zero and make each subclass initialiser point the static function pointer to a static function. That way, given a base object pointer p, you could probably use p->run in the way you want. -- JDL Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.