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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:03:05+00:00 2026-05-23T00:03:05+00:00

Hi I am trying to pass a callback which is a member function. I

  • 0

Hi
I am trying to pass a callback which is a member function. I understand that a function pointer and a member function pointer are different and have tried to create a wrapper and use a static cast and the void pointer. Unfortunately I am missing something as my code produces an error at compile

Error   16  error C2664: 'dSpaceCollide' : cannot convert parameter 3 from 'int (__cdecl *)(void *,void *,dGeomID,dGeomID)' to 'dNearCallback (__cdecl *)'  

My code…..

class ODEPhysics

header file

void NearCallback (void* data, dGeomID o1, dGeomID o2);
static int StaticNearCallback(void* data, void* userPtr, dGeomID o1, dGeomID o2);

.cpp file
void ODEPhysics::NearCallback (void* data, dGeomID o1, dGeomID o2){.........}

void ODEPhysics::StaticNearCallback(void* data , void* userPtr, dGeomID o1, dGeomID o2)
{
      static_cast<ODEPhysics*>(userPtr)->NearCallback( data, o1,  o2);


}

dSpaceCollide (Space, 0, &ODEPhysics::StaticNearCallback); 

If anyone could clarify what I am doing wrong and why it would be greatly appreciated.

Fred

  • 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-23T00:03:06+00:00Added an answer on May 23, 2026 at 12:03 am

    The problem is most likely, from what you show, that dSpaceCollide just wants a

    typedef void (*dNearCallback)(void*,dGeomID,dGeomID)
    

    callback, that is, a function with a single void* user-data pointer and the two dGeomIDs as parameters. The void* is whatever data you passed to the dSpaceCollide then.

    Assuming dSpaceCollide is defined something like this:

    void dSpaceCollide(CSpace s, void* user_data, dNearCallback cb){
      // somewhere inside the code it will call your callback:
      cb(user_data, some_other, params);
      // ...
    }
    

    You can then change the callbacks to this:

    void NearCallback(dGeomID o1, dGeomID o2);
    static void StaticNearCallback(void* data, dGeomID o1, dGeomID o2){
      ODEPhysics* self = static_cast<ODEPhysics*>(data);
      self->NearCallback(o1, o2);
    }
    

    No more need for the void* data pointer in the member function, as that data is only relevant for the static callback:

    // assuming you call this inside of your ODEPhysics class
    dSpaceCollide(Space, this, &ODEPhysics::StaticNearCallback);
    // pass this as user_data
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pass a member function to libevent which should be treated
I am trying to pass a member function within a class to a function
I'm trying to pass one method to another in elisp, and then have that
I'm trying to pass some parameter to a function used as callback , how
I am trying to pass a callback function from C++ to OpenGL (C API):
I have a function call in my script that contain a callback function call
im trying to pass two parameters to a function, i being an int value
I'm trying to pass a complex object (that can be serialized, if that helps)
I am trying to get and pass a rel attr to tell which tab
I am attempting to pass function scope to a callback method. The problem I

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.