Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing a member function from another class without prior knowledge of the specific member function
    text
    copied!<p>I want to create a class that will access the member functions of a family of classes. Going into more detail, I have class ControlChaos which is declared like this:</p> <pre><code>#define CALL_MEMBER_FN(object, ptrToMember) ((object)-&gt;*(ptrToMember)) typedef double (MultiMaps::*mapsGetPtr)(); typedef void (MultiMaps::*mapsSetPtr)(double para); class ControlChaos { public: ControlChaos(MultiMaps* _map, mat orbitPoints, colvec initCond, mapsGetPtr getPtr, mapsSetPtr setPtr, double deltaMax, double epsilonNeighborhood, int controlIterations, int maxIterations); /* Other stuff here. */ }; </code></pre> <p>with protected member variables which are of type mapsGetPtr and mapsSetPtr, and others. In the implementation, I use </p> <pre><code> CALL_MEMBER_FN(map,setPtr)(someParameter); </code></pre> <p>to call the function which I specified using a function pointer in the constructor of ControlChaos. The member functions I want to access are members of classes derived from MultiMaps. This code, by itself, compiles fine. When I try to instantiate a ControlChaos object with a function pointer pointing to a member function in a class derived from MultiMaps, then the compiler complains that I gave it the wrong argument type. </p> <p>Moreover, this <a href="http://www.codeproject.com/Articles/7150/Member-Function-Pointers-and-the-Fastest-Possible" rel="nofollow">article</a> seems to imply that a static cast could do the job, but I haven't found this to be true. </p> <p>Any ideas on how to solve this?</p>
 

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