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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:18:06+00:00 2026-05-15T08:18:06+00:00

visual studio tells me error C2664: ‘boost::asio::mutable_buffer::mutable_buffer(const boost::asio::mutable_buffer&)’: impossible to convert parameter 1 from

  • 0

visual studio tells me “error C2664: ‘boost::asio::mutable_buffer::mutable_buffer(const boost::asio::mutable_buffer&)’: impossible to convert parameter 1 from ‘char’ to ‘const boost::asio::mutable_buffer&’ at line 163 of consuming_buffers.hpp”

I am unsure of why this happen nor how to solve it(otherwise I wouldn’t ask this ^^’) but I think it could be related to those functions.. even tough I tried them in another project and everything worked fine… but I can hardly find what’s different

so… here comes code that could be relevant, if anything useful seems to be missing I’ll be glad to send it.

packets are all instances of this class.

class CPacketBase
{
protected:
 const unsigned short _packet_type;
 const size_t _size;
 char* _data;

public:
 CPacketBase(unsigned short packet_type, size_t size);
 ~CPacketBase();

 size_t get_size();
 const unsigned short& get_type();
 virtual char* get();
 virtual void set(char*);
};

this sends a given packet

    template <typename Handler> 
 void async_write(CPacketBase* packet, Handler handler)
 {
  std::string outbuf;
  outbuf.resize(packet->get_size());
  outbuf = packet->get();
  boost::asio::async_write( _socket
   , boost::asio::buffer(outbuf, packet->get_size())
   , handler);
 }

this enable reading packets and calls a function that decodes the packet’s header(unsigned short) and resize the buffer to send it to another function that reads the real data from the packet

template <typename Handler> 
 void async_read(CPacketBase* packet, Handler handler)
 {
  void (CTCPConnection::*f)( const boost::system::error_code&
      , CPacketBase*, boost::tuple<Handler>)
       = &CTCPConnection::handle_read_header<Handler>;
  boost::asio::async_read(_socket, _buffer_data
   , boost::bind( f
    , this
    , boost::asio::placeholders::error
    , packet
    , boost::make_tuple(handler)));
 }

and this is called by async_read once a packet is received

template <typename Handler> 
 void handle_read_header(const boost::system::error_code& error, CPacketBase* packet, boost::tuple<Handler> handler)
 {
  if (error)
  {
   boost::get<0>(handler)(error);
  }
  else
  {
   // Figures packet type
   unsigned short packet_type = *((unsigned short*) _buffer_data.c_str());

   // create new packet according to type
   delete packet;
   ...

   // read packet's data
   _buffer_data.resize(packet->get_size()-2); // minus header size

   void (CTCPConnection::*f)( const boost::system::error_code&
     , CPacketBase*, boost::tuple<Handler>)
       = &CTCPConnection::handle_read_data<Handler>;
   boost::asio::async_read(_socket, _buffer_data
    , boost::bind( f
     , this
     , boost::asio::placeholders::error
     , packet
     , handler));
  }
 }
  • 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-15T08:18:07+00:00Added an answer on May 15, 2026 at 8:18 am

    Based on this line of code…

    unsigned short packet_type = *((unsigned short*) _buffer_data.c_str());
    

    …I’m guessing you are using a std::string as the type for _buffer_data and attempting to read data into it using boost::asio::async_read. You can’t do that (see my answer here for an explanation: How to asynchronously read to std::string using Boost::asio?)

    You could try using one of the factory overloads of boost::asio::buffer and using a POD type such as char *. For example:

    char * _buffer_data = new char[packet->get_size()-2];
    boost::asio::async_read(
        _socket, 
        boost::asio::buffer(_buffer_data, packet->get_size()-2), 
        //....
    

    (I’ve not tested this, but in theory it should create a mutable buffer wrapping a raw char array that has at most packet->get_size()-2 bytes. Makes sense…)

    You could also try using a boost::shared_array<char> instead, but I’m not sure that can be implicitly converted to a mutable buffer either, so you’d have to roll your own “mutable buffer.” Note that since boost::asio::async_read is a template function, the second parameter’s type is not strictly defined, and can actually be anything that adheres to the mutable buffers concept. See this page for more info on that: http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/reference/MutableBufferSequence.html

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

Sidebar

Ask A Question

Stats

  • Questions 441k
  • Answers 441k
  • 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 Turns out the problem was triggered by the frequency of… May 15, 2026 at 5:29 pm
  • Editorial Team
    Editorial Team added an answer At the moment I can't find my full wrapper for… May 15, 2026 at 5:29 pm
  • Editorial Team
    Editorial Team added an answer Yeah it's possible. Button myBtn = (Button)findViewById(R.id.myButtonId); myBtn.requestFocus(); or in… May 15, 2026 at 5:29 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.