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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:00:17+00:00 2026-05-11T05:00:17+00:00

I dislike having magic boxes scattered all over my code…how exactly do these two

  • 0

I dislike having magic boxes scattered all over my code…how exactly do these two classes work to allow basically any function to be mapped to a function object even if the function<> has a completely different parameter set to the one im passing to boost::bind

It even works with different calling conventions (i.e. member methods are __thiscall under VC, but ‘normal’ functions are generally __cdecl or __stdcall for those that need to be compatible with C.

  • 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. 2026-05-11T05:00:17+00:00Added an answer on May 11, 2026 at 5:00 am

    boost::function allows anything with an operator() with the right signature to be bound as the parameter, and the result of your bind can be called with a parameter int, so it can be bound to function<void(int)>.

    This is how it works (this description applies alike for std::function):

    boost::bind(&klass::member, instance, 0, _1) returns an object like this

    struct unspecified_type {   ... some members ...   return_type operator()(int i) const { return instance->*&klass::member(0, i); } 

    where the return_type and int are inferred from the signature of klass::member, and the function pointer and bound parameter are in fact stored in the object, but that’s not important

    Now, boost::function doesn’t do any type checking: It will take any object and any signature you provide in its template parameter, and create an object that’s callable according to your signature and calls the object. If that’s impossible, it’s a compile error.

    boost::function is actually an object like this:

    template <class Sig> class function {   function_impl<Sig>* f; public:   return_type operator()(argument_type arg0) const { return (*f)(arg0); } }; 

    where the return_type and argument_type are extracted from Sig, and f is dynamically allocated on the heap. That’s needed to allow completely unrelated objects with different sizes bind to boost::function.

    function_impl is just an abstract class

    template <class Sig> class function_impl { public:   virtual return_type operator()(argument_type arg0) const=0; }; 

    The class that does all the work, is a concrete class derived from boost::function. There is one for each type of object you assign to boost::function

    template <class Sig, class Object> class function_impl_concrete : public function_impl<Sig> {   Object o public:   virtual return_type operator()(argument_type arg0) const=0 { return o(arg0); } }; 

    That means in your case, the assignment to boost function:

    1. instantiates a type function_impl_concrete<void(int), unspecified_type> (that’s compile time, of course)
    2. creates a new object of that type on the heap
    3. assigns this object to the f member of boost::function

    When you call the function object, it calls the virtual function of its implementation object, which will direct the call to your original function.

    DISCLAIMER: Note that the names in this explanation are deliberately made up. Any resemblance to real persons or characters … you know it. The purpose was to illustrate the principles.

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

Sidebar

Ask A Question

Stats

  • Questions 378k
  • Answers 378k
  • 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 Indeed, the following line is wrong: Return Encoding.Default.GetString(Crypt(Encoding.Default.GetBytes(Data))) There's no… May 14, 2026 at 9:08 pm
  • Editorial Team
    Editorial Team added an answer In Visual Studio, right-clicking on a class and selecting Go… May 14, 2026 at 9:08 pm
  • Editorial Team
    Editorial Team added an answer You might need to specify the template directories in settings.py,… May 14, 2026 at 9:08 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

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.