Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7965069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:03:23+00:00 2026-06-04T06:03:23+00:00

Hello I am trying to write a small program to simulate dynamical systems using

  • 0

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

In the current design I want to have an abstract Experiment 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 Experiment class and only override the two virtual functions with the specific class which will be inherited by the Experiment.

The problem I have is that as virtual these methods do not compile

error: argument of type ‘int (Experiment::)(double, const double*, double*, void*)’ does not match ‘int (*)(double, const double*, double*, void*)’

If I make these two functions static the program compiles but I am losing the functionality that I want to achieve for specific problems.

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?

Thanks in advance.

EDIT: THe code below compiles but they are not virtual

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, &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
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:03:24+00:00Added an answer on June 4, 2026 at 6:03 am

    I presume the void* in your function definition is a user-specified callback parameter. In that case, use this parameter to pass a pointer to your object and make your callback a static function. Inside this static function, cast this pointer back to the proper type (Experiment*) and call the non-static version of the function.

    class Experiment
    {
    public:
        Experiment();
        ~Experiment();
    
        void setupExperiment();
        static int static_func(double t, const double y[], double f[], void *params);
        static int static_jac (double t, const double y[], double *dfdy, double dfdt[], void *params);
        virtual int func(double t, const double y[], double f[]);
        virtual int jac (double t, const double y[], double *dfdy, double dfdt[]);
    };
    
    void Experiment::setupExperiment()
    {
        gsl_odeiv2_system sys = {static_func, static_jac, 2, this}; //Here is the problem with virtual functions
    }
    
    int Experiment::static_func(double t, const double y[], double f[], void *params)
    {
      return ((Experiment*)params)->func(t, y, f);
    }
    
    int Experiment::static_jac (double t, const double y[], double *dfdy, double dfdt[], void *params)
    {
      return ((Experiment*)params)->jac(t, y, dfdy, dfdt);
    }
    
    class aSpecificProblem: public Experiment
    {
    public:
        virtual int func(double t, const double y[], double f[]);
        virtual int jac (double t, const double y[], double *dfdy, double dfdt[]);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a hello world type program for using virtual channels
I am trying to write a RESTFul Webservice using Jersey. package sample.hello.resources; @Path(/hello) public
I'm trying to write a program that manipulates unicode strings read in from a
Hello I am trying to write a program in python that asks the user
Hello I'm trying to write some tool using code::blocks, wxWidgets and libxml2 on Windows
i am trying to write a boot loader(hello world sort). i am using Bochs
I am trying to write a small program, that opens a server, creates a
I'm trying to write a small client server program. The Server is in C#,
Hello World :) I'm trying to write MIXINS for BOX-SHADOW property using SASS like
Hello i am trying to write the following function to display 7 days of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.