绑定与提升工作,而与std不同,是什么意思?

时间:2013-05-23 00:12:39

标签: boost boost-bind stdbind

我试图用std :: bind绑定一个函数,它一直说我的参数集没有重载。它适用于boost :: bind。什么是std和boost绑定之间的差异?

我正在使用:

  

Microsoft Visual Studio Ultimate 2012版本11.0.60315.01更新2

     

提升1.53.0

func声明和绑定:

void Messenger::receiveCallback(const boost::system::error_code& error, size_t bytes_transferred, char* message, int bufferSize, tcp::socket* socketPtr, void(*onMessageReceivedCallback)(char* message, string hostname, int port, int length));

std::bind(&Messenger::receiveCallback, this, std::placeholders::_1, std::placeholders::_2, message, bufferSize, socketPtr, onMessageReceivedCallback);//error

boost::bind(&Messenger::receiveCallback, this, _1, _2, message, bufferSize, socketPtr, onMessageReceivedCallback);

错误:

  

105 IntelliSense:没有重载函数的实例“std :: bind”   匹配参数列表               参数类型是:(void(Messenger :: *)(const boost :: system :: error_code& error,size_t bytes_transferred,char   * message,int bufferSize,boost :: asio :: ip :: tcp :: socket * socketPtr,void(* onMessageReceivedCallback)(char * message,std :: string hostname,   int port,int length)),Messenger *,std :: _ Ph< 1&gt ;,std :: _ Ph< 2>,char *,   int,boost :: asio :: ip :: tcp :: socket ,void()(char * message,   std :: string hostname,int port,int   长度))c:\ Users \ gospo_000 \ Source \ Repos \ Messenger \ Messenger \ Messenger \ Messenger.cpp 176 4 Messenger

     

很多像这样的错误:

     

错误81错误C2780:   “enable_if ::价值的std :: _ BindRx(_thiscall   _Farg0 :: *)(_ V0_t,_V1_t,_V2_t,_V3_t,_V4_t),_ Rx,_Farg0,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t>,_ Vx0_t,_Vx1_t>> :: type std :: bind( Rx ( _thiscall _Farg0 :: * const   )(_ V0_t,_V1_t,_V2_t,_V3_t,_V4_t),_ Vx0_t&&,_ Vx1_t&&)':期望3   争论 - 8   提供c:\ users \ gospo_000 \ source \ repos \ messenger \ messenger \ messenger \ messenger.cpp 176 1 tester2

Messenger.h

#include <string>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include "Connection.h"
#include "Message.h"
#include <unordered_map>

using namespace std;
using namespace boost::asio;
using boost::asio::ip::tcp;


class Messenger
    {
   //.............................
          void receiveCallback(const boost::system::error_code& error, size_t bytes_transferred, char* message, int bufferSize, tcp::socket* socketPtr, void(*onMessageReceivedCallback)(char* message, string hostname, int port, int length));
    };

Messenger.cpp

void Messenger::receiveCallback(const boost::system::error_code& error, size_t bytes_transferred, char* message, int bufferSize, tcp::socket* socketPtr, void(*onMessageReceivedCallback)(char* message, string hostname, int port, int length))
{
    if(error)
    {
        string connectionId = getConnectionId(socketPtr->remote_endpoint());
        connections_.erase(connectionId);
        cout<<error.message();
    }
    else
    {
        onMessageReceivedCallback(message, socketPtr->remote_endpoint().address().to_string(), socketPtr->remote_endpoint().port(), bytes_transferred);
        socketPtr->async_receive(
            boost::asio::buffer(message, bufferSize),
            boost::bind(&Messenger::receiveCallback, this, _1, _2, message, bufferSize, socketPtr, onMessageReceivedCallback));
    }
}

1 个答案:

答案 0 :(得分:1)

不同之处在于std::bind默认只占用5 arguments。将_VARIADIC_MAX宏设置为10,以便增加可变参数模板中的最大arg数。