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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:29:16+00:00 2026-06-16T12:29:16+00:00

I’m having some trouble making a callback wrapper class method that needs to be

  • 0

I’m having some trouble making a callback wrapper class method that needs to be used by a third party library; the JackAudio library.

I have been able to make a wrapper for a JackAudio callback function that needs two arguments.

I’m just having trouble creating a callback function for a particular function that needs a const char * as an argument.

So far I have been able to make the JackAudio library jack_set_sample_rate_callback function use a custom class and can be executed like so:

SoundClass Sound;

SoundClass * SoundPointer = &Sound;

jack_set_sample_rate_callback( 
                              client, 
                              SoundClass::SampleRateCallbackWrapper, 
                              SoundPointer 
                             );

And the class looks something like this:

SoundClass
{

int SampleRateCallback( jack_nframes_t nframes )

    {
        //executes some code when called.
    }

 static int SampleRateCallbackWrapper( jack_nframes_t nframes, void * arg )
    {
        return static_cast < SoundClass* > ( arg )->SampleRateCallback( nframes );
    }
};

All of the above works well, with no issues.

The problem I’m having now is with the JackAudio callback function jack_set_error_function

This is what I tried:

static void  ErrorCallbackWrapper( const char * arg  )
{
    return static_cast < SoundClass*>( arg )->SomeErrorFunction();
}

But I get error: invalid static_cast from type ‘const char*’ to type ‘SoundClass*’

I get the gist why this is happening, I just have no idea what to do for a solution.

Thanks in advance for any help guys.

  • 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-16T12:29:17+00:00Added an answer on June 16, 2026 at 12:29 pm

    Assuming the Jack API is written for the C language, there is a formal problem already with the working callback that you have. Namely that it then needs to be extern "C", and that as a static member function it cannot be. So formally it needs to be a free-standing function.

    The documentation that you link to for the jack_set_error_function gives this signature, presumably expressed in C:

    void jack_set_error_function( void(*)(const char *) func);
    

    For C++ the callback must be assumed to be extern "C", so,

    extern "C" void MyErrorFunction( char const* errorMessage )
    {
        // Whatever, e.g. post a message to the GUI event queue, or terminate.
    }
    

    If you want this function to in turn call a method on an object, then unless the library provides some special mechanism to help you, you will just have to use one of the following techniques:

    • a namespace scope variable accessed by the callback, or

    • a dynamically generated callback.

    C++ does not as of yet support the second approach, at all, so the first one is strongly indicated – if you want a callback on a method of an object.


    EDIT: Sorry, I forgot to mention,

            the function declarations in the API documentation are syntactically invalid.

    E.g. the documentation’s signature

    void jack_set_info_function( void(*)(const char *) func );
    

    simply won’t compile with a standard-conforming compiler. Not as C, and not as C++. It’s syntactically invalid in both languages.

    Instead it should be

    void jack_set_info_function( void(*func)(const char *) );
    

    Since the documentation apparently is generated by DOxygen, it stands to reason that it’s been generated from source code that compiles. If so then this is a bug in DOxygen, and a problem with the quality assurance of the library provider. However it might be a problem that lies solely with the library provider, or, I might be mistaken in the assumption that this is a C library?

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. 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.