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

  • Home
  • SEARCH
  • 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 6828437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:22:58+00:00 2026-05-26T22:22:58+00:00

I am trying the following: boost::shared_ptr< tcp::socket > socket(new tcp::socket( *io_service)); boost::bind(&function, *socket); //

  • 0

I am trying the following:

boost::shared_ptr< tcp::socket > socket(new tcp::socket( *io_service));

boost::bind(&function, *socket); // compiler error: noncopyable error
function(*socket); // this works fine

void
function(tcp::socket & socket)
{
   //do work
}

Why do I get an error there using boost::bind?

I later tried the following:

boost::shared_ptr< tcp::socket > socket(new tcp::socket( *io_service));
boost::bind(&function, socket); //this works fine now
void function(boost::shared_ptr< tcp::socket > socket)
{
   asio::read_until(&socket, buffer, "end"); // compiler error: says i am passing an invalid argument
}

Why doesn’t this work now?

I know I am lacking basic knowledge of C/C++ programming.

If anyone could include a link that helps with issues like this, it would be great.

  • 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-26T22:22:59+00:00Added an answer on May 26, 2026 at 10:22 pm

    tcp::socket is non-copyable, you need to pass it as a reference:

    boost::bind(&function, boost::ref(*socket)); 
    

    You should probably stick to your second version as you will not have to worry about life-time of the socket object.

    boost::bind(&function, socket); 
    void function(boost::shared_ptr< tcp::socket > socket)
    {
       asio::read_until(*socket, buffer, "end");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to bind a boost asio tcp socket to a local network interface
I am trying to pass a function pointer using boost::bind. void Class::ThreadFunction(Type(*callbackFunc)(message_type::ptr&)) { }
Following the advice of this page , I'm trying to get shared_ptr to call
I'm trying to build the boost examples. I get the following error: Access is
I'm trying the following: CREATE TABLE Table1 ( RecordNo autonumber, --error here! PersonId varchar(50),
I'm new to Ruby, and I'm trying the following: mySet = numOfCuts.times.map{ rand(seqLength) }
I am trying to do the following: boost::unordered_map<boost::flyweight<std::string>, boost::flyweight<std::string> > map; boost::flyweight<std::string> foo(name); map[foo]
I am trying to install Boost on an unix cluster machine following the Boost
I am following these instructions trying to build Boost MPI .lib files, but I
Trying to build the following simple example #include <boost/python.hpp> using namespace boost::python; tuple head_and_tail(object

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.