Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic Virtual workaround in GSL
    primarykey
    data
    text
    <p>Hello I am trying to write a small program to simulate dynamical systems using the differential equation package from the GNU Scientific Library. The problem is not specific to the GSL but I am just giving you all the details</p> <p>In the current design I want to have an abstract <code>Experiment</code> class, where all the complex functions will be called by the gsl library. The dynamics of the explicit system will be defined by two functions, i.e., func and jacob, that define the specific motion equations and the jacobian respectively. Thus, I want to do all the simulation in the <code>Experiment</code> class and only override the two virtual functions with the specific class which will be inherited by the <code>Experiment</code>.</p> <p>The problem I have is that as virtual these methods do not compile</p> <p><code>error: argument of type ‘int (Experiment::)(double, const double*, double*, void*)’ does not match ‘int (*)(double, const double*, double*, void*)’</code></p> <p>If I make these two functions static the program compiles but I am losing the functionality that I want to achieve for specific problems.</p> <p>Apparently, they cannot be both static and virtual, so does anyone know any workaround to this problem? Are there any suggestions to better approach it?</p> <p>Thanks in advance.</p> <p>EDIT: THe code below compiles but they are not virtual</p> <pre><code>class Experiment { public: Experiment(); ~Experiment(); void setupExperiment(); static int func(double t, const double y[], double f[], void *params); static int jac (double t, const double y[], double *dfdy, double dfdt[], void *params); }; void Experiment::setupExperiment(){ double mu = 10; gsl_odeiv2_system sys = {func, jac, 2, &amp;mu}; //Here is the problem with virtual functions } class aSpecificProblem: public Experiment{ // I want to implement just the func and jac function which should be virtual above }; </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.
    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