Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic function needing to deal with members of a C++ class
    primarykey
    data
    text
    <p>I have to make some kind of bridge between two pieces of software, but am facing an issue I don't know how to deal with. Hopefully someone will have interesting and (preferably) working suggestions.</p> <p>Here is the background : I have a C++ software suite. I have to replace some function within a given class with another function, which is ok. The problem is that the new function calls another function which has to be static, but has to deal with members of the class. This is this second function which is making me mad.</p> <p>If the function is not static I get the following error :</p> <pre><code>error: argument of type ‘void (MyClass::)(…)’ does not match ‘void (*)(…)’ </code></pre> <p>If I set it to static I get either the following error :</p> <pre><code>error: cannot call member function ‘void MyClass::MyFunction(const double *)’ without object </code></pre> <p>or </p> <pre><code>error: ‘this’ is unavailable for static member functions </code></pre> <p>depending on if I use or not the "this" keyword ("Function()" or "this->Function()").</p> <p>And finally, the class object requires some arguments which I cannot pass to the static function (I cannot modify the static function prototype), which prevents me to create a new instance within the static function itself.</p> <p>How would you deal with such a case with minimal rewriting ? </p> <p>Edit : Ok, here is a simplified sample on what I have to do, hoping it is clear and correct :</p> <pre><code>// 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&amp; result) { // doesn't work because fcn is static result = SomeComputation(); // doesn't work, for the same reason result = this-&gt;SomeComputation(); // doesn't work either, because MyClass has many parameters // which have to be set MyClass *tmp = new MyClass(); result = tmp-&gt;SomeComputation(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload