I need to make some kind of bridge between the two pieces of software, but I ran into a problem that I donβt know how to deal with. I hope someone will have interesting and (preferably) working suggestions.
Here is the background: I have a C ++ software package. I have to replace some function inside this class with another function, which is normal. The problem is that the new function calls another function, which must be static, but must deal with class members. This is the second feature that makes me crazy.
If the function is not static, I get the following error:
error: argument of type 'void (MyClass::)(β¦)' does not match 'void (*)(β¦)'
If I set it to static, I get either the following error:
error: cannot call member function 'void MyClass::MyFunction(const double *)' without object
or
error: 'this' is unavailable for static member functions
depending on whether or not I use the keyword "this" ("Function ()" or "this-> Function ()").
And finally, the class object requires some arguments that I cannot pass to the static function (I cannot change the prototype of the static function), which prevents me from creating a new instance inside the static function itself.
How do you feel about such a case with minimal rewriting?
Edit: Well, here is a simplified example of what I should do, hoping this is clear and correct:
// This function is called by another class on an instance of MyClass MyClass::BigFunction() { β¦ // Call of a function from an external piece of code, // which prototype I cannot change XFunction(fcn, some more args); β¦ } // This function has to be static and I cannot change its prototype, // for it to be passed to XFunction. XFunction makes iterations on it // changing parameters (likelihood maximization) which do not appear // on this sample void MyClass::fcn(some args, typeN& result) { // doesn't work because fcn is static result = SomeComputation(); // doesn't work, for the same reason result = this->SomeComputation(); // doesn't work either, because MyClass has many parameters // which have to be set MyClass *tmp = new MyClass(); result = tmp->SomeComputation(); }