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 6612885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:09:05+00:00 2026-05-25T20:09:05+00:00

This is very likely an extremely basic question – sorry about that. I have

  • 0

This is very likely an extremely basic question – sorry about that.

I have written an interface in C++ which is powered by a C engine. One of the C-engine functions has the following signature:

static int f(double t, double *y, double *ydot, void *data)

The *data thingy is to pass user data to an ODE solver. Now, in C I would simply create an struct, initialize it with my data, and pass it around. In C++ I want to create a class containing the user data, and pass it as I previously passed the struct. This can be done, as structs are classes.

However, when I try to do it, the following happens:

int.cpp:25: error: no matching function for call to ‘UserData::UserData()’
int.cpp:13: note: candidates are: UserData::UserData(double)
int.cpp:5: note:                 UserData::UserData(const UserData&)
int.cpp:28: error: ‘void*’ is not a pointer-to-object type
int.cpp:29: error: ‘void*’ is not a pointer-to-object type

My questions are the following:

  1. What does the void *data notation mean?
  2. Why is it complaining that I don’t have a constructor with the appropriate signature?

Obviously I am very much a rookie, so I’m sorry if this is very obvious, but I don’t even know what terms to use to google the problem (in addition to googling the error itself).

Thanks!

Edit:

I apologize for the vagueness of the previous question. Also, I solved the problem and it was a very stupid mistake.

I had a class containing parameters:

class Data{
// an interface to get parameters
};

and I needed to call a C function with the signature

static int f(double t, ...., void *user_data)

I mistakenly did this:

static int f(double t, ...., void *user_data){
 Data *data = (Data*) data; /* this is the stupid mistake */
}

When I meant to do this (now it works):

static int f(double t, ...., void *user_data){
 Data *data = (Data*) user_data; /* this is the correction  */
}

Thank you all – and I appreciate indicating the correct meaning of void *data.

  • 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-05-25T20:09:05+00:00Added an answer on May 25, 2026 at 8:09 pm
    void *data 
    

    means a pointer to any address. It is a non-typesafe way of passing data of arbitrary type. It is a common pattern in C to implement what would be done with a function object in C++. The data parameter is probably not actually used by your ODE solver, but by a callback that you are providing. You and the callback need to know the what data points to, the ODE solver doesn’t. The solver just passes the address to the callback function.

    As simple example, suppose the library had a function to find the root of a function in a single variable

      typedef double (*valuation_function) (double x, void * params);
      double find_root(valuation_function fn, double lower, double upper, void* params);
    

    The params function gives you the ability to write a parameterized function. Suppose you wanted to find the root of a line.

    struct Line {
      double slope;
      double intercept;
      public:
         Line(double s, double i) : slope(s), intercept(i) {}
    };
    
    double a_line(double x, void *params) {
      Line* line = (Line *)params;
      return line->slope * x + line->intercept;
    }
    

    You could then call the function find_root for any line.
    Line fortyFive(1.0, 0.0);
    find_root(a_line, fortyFive);

    You can look at the gsl library for more examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This issue is very likely codeigniter specific. I have a controller called redirect.php that
I realize this question is very likely to have been asked before, but I've
I'm sorry for this very newbish question, I'm not much given into web development.
Okay this could very likely be a silly question. I am using Entity Framework
Very likely I'm going about this in the wrong way entirely. I'm completely new
Since in log4j javadoc is WARNING: This version of JDBCAppender is very likely to
I've written this very simple function to replace a file extension using LINQ in
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
Important : Please see this very much related question: Return multiple values in C++
I've been stuck on this likely very simple problem, but haven't gotten anywhere with

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.