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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:55:25+00:00 2026-05-16T03:55:25+00:00

want to pass boost::bind to a method expecting a plain function pointer (same signature).

  • 0

want to pass boost::bind to a method expecting a plain function pointer (same signature).

typedef void TriggerProc_type(Variable*,void*);
void InitVariable(TriggerProc_type *proc);
boost::function<void (Variable*, void*)> triggerProc ...
InitVariable(triggerProc);

error C2664: 'InitVariable' : cannot convert parameter 1 from 
'boost::function<Signature>' to 'void (__cdecl *)(type *,void *)'

I can avoid storing a boost::function and just pass the bound functor directly, but then I get similar error:

error C2664: 'blah(void (__cdecl *)(type *,void *))' : cannot convert parameter
1 from 'boost::_bi::bind_t<R,F,L>' to 'void (__cdecl *)(type *,void *)'
  • 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-16T03:55:26+00:00Added an answer on May 16, 2026 at 3:55 am

    Has anyone noticed that the accepted answer only works with trivial cases? The only way that function<>::target() will return an object that can be bound to a C callback, is if it was constructed with an object that can be bound to a C callback. If that’s the case, then you could have bound it directly and skipped all of the function<> nonsense to begin with.

    If you think about it, there isn’t any magic solution to this. A C-style callback is stored as a single pointer which points to executable code. Any nontrivial boost::function<> is going to need at least two pointers: one to the executable code, the other to the data that’s needed to set up the call (e.g. the ‘this’ pointer, in the case of a bound member function).

    The right way to use boost::function and boost::bind with C callbacks is to create a shim function that satisfies the callback signature, figures out which function<> to call, and calls it. Usually C callbacks will have some kind of a void* for ‘user data’; that’s where you stash your function pointer:

    typedef void (*CallbackType)(int x, void* user_data);
    void RegisterCallback(CallbackType cb, void* user_data);
    
    void MyCallback(int x, void* userData) {
      boost::function<void(int)> pfn = static_cast<boost::function<void(int)> >(userData);
      pfn(x);
    }
    
    boost::function<void(int)> fn = boost::bind(myFunction(5));
    RegisterCallback(MyCallback, &fn);
    

    Of course, if your callback signature doesn’t include some kind of user data pointer, you’re out of luck. But any callback that doesn’t include a user data pointer is already unusable in most real-world scenarios, and needs to be rewritten.

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

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm not aware of reentrant versions of dirname and basename… May 16, 2026 at 4:53 pm
  • Editorial Team
    Editorial Team added an answer If you want full control over the style, you can… May 16, 2026 at 4:53 pm
  • Editorial Team
    Editorial Team added an answer Use the phone Imei as described here: http://www.androidsoftwaredeveloper.com/2009/04/02/how-to-get-the-phone-imei/ String imei… May 16, 2026 at 4:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

You can pass a function pointer, function object (or boost lambda) to std::sort to
Do you have to pass delete the same pointer that was returned by new,
I want to pass a fairly generic set of data through a WCF method.
I want to create a alias method in ruby and pass parameters to this.
I have a function that I want to pass an argument to, however I
I want to pass a parameter, when i click submit button. urls.py urlpatterns =
I want to pass xml document to sql server stored procedure such as this:
I want to pass multiple parameter but I don't know the numbers. Such as
I'm new to JasperReports . I want to pass ArrayList to subreport of subreport.
How can I convert 755 to 0755 in Ruby? I want to pass permissions

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.