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

The Archive Base Latest Questions

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

When I use boost::bind to bind parameters to a function – when are they

  • 0

When I use boost::bind to bind parameters to a function – when are they casted to the type required by the function (if an implicit cast is possible)?

How are they stored in the bind_t object? As the type originally passed to bind or as the type required by the function signature?

Specifically:

If I have a function of the signature

void SomeFun(SmartPointer<SomeType>)

and I use bind as

boost::bind(&SomeFun, somePtr)

where somePtr is of type SomeType*, will the bind_t object contain a copy of somePtr stored as a simple pointer or will it be casted to the SmartPointer<SomeType> and be stored as a SmartPointer<SomeType>?

There is an implicit cast from SomeType* to SmartPointer<SomeType>. As opposed to boost::shared_ptr this SmartPointer uses a reference counter in the managed objects, meaning SomeType has to be derived from SmartPointed.

  • 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-19T03:03:56+00:00Added an answer on May 19, 2026 at 3:03 am

    This won’t even work as there is no implicit conversion or implicit constructor to shared_ptr from SomeType*.

    You should call

    boost::bind(&SomeFun, boost::shared_ptr<SomeType>(somePtr))
    

    if somePtr is a pointer you have just allocated with “new” and expect to be deleted later when the last reference of the shared_ptr goes out of scope. If you don’t want the pointer to be deleted but you know it will still be valid at the time of the call, and the function must take shared_ptr, you can use a no-op deleter to create the shared_ptr. Either way, it is a shared_ptr, not a pointer or a weak_ptr or anything else you must pass in in this instance.

    You say your case is different so we would have to see your actual case or one that matches it closer.

    You may be getting confused with the case where the function you pass in is a class member function and you pass in the class instance (the object) as one of the parameters. Here you can pass in a pointer, a reference or a shared_ptr and it can be a const reference if the function is a const-method (similarly pointer-to-const or shared_ptr to const).

    That is simply because there are different overloads to boost::bind for all these when the function is a class member function.

    Where the conversion is implicit the implicit conversion will happen at the time the function is called. boost::bind is just a template that stored what is passed into it.
    Some magic will occur with the first parameter if it is used to call a member function.

    Note that sometimes boost::bind will store a boost::ref where the function actually takes a reference.

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

Sidebar

Related Questions

Is it possible to use boost::fusion::invoke function to call a function that has default
I'm trying to use boost::bind with the std::sort function. I want to bind sort
I have a situation where a boost::function and boost::bind (actually a std::tr1::function and bind)
I noticed that when passing reference parameters to boost bind, those parameters won't act
Is it somehow possible to use boost::object_pool<>::construct with non const references? The following snippet
Now I am try to use boost bind & mem_fn . But there's a
I want to use a boost::function and pass it to a function to function
I'd like to use the boost::transform_iterator together with boost::bind to return the result of
I'm trying to use boost::signal to implement a callback mechanism, and I'm getting a
I thought I'd use Boost.Interprocess's Message Queue in place of sockets for communication within

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.