Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
与boost绑定有效,而与std绑定无效,有什么区别?_Boost_Boost Bind_Stdbind - Fatal编程技术网

与boost绑定有效,而与std绑定无效,有什么区别?

与boost绑定有效,而与std绑定无效,有什么区别?,boost,boost-bind,stdbind,Boost,Boost Bind,Stdbind,我尝试用std::bind绑定函数,它一直说我的参数集没有重载。它与boost::bind一起工作。std和boost绑定之间有什么区别 即时通讯使用: Microsoft Visual Studio Ultimate 2012版本11.0.60315.01更新2 boost 1.53.0 func声明和绑定: void Messenger::receiveCallback(const boost::system::error_code& error, size_t bytes_tran

我尝试用std::bind绑定函数,它一直说我的参数集没有重载。它与boost::bind一起工作。std和boost绑定之间有什么区别

即时通讯使用:

Microsoft Visual Studio Ultimate 2012版本11.0.60315.01更新2

boost 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\u code&error,size\u t bytes\u transfer,char) *消息,int bufferSize,boost::asio::ip::tcp::socket*socketPtr,void(*onMessageReceivedCallback)(char*消息,std::字符串主机名, int端口,int长度),信使*,标准::_Ph,标准::_Ph,字符*, int,boost::asio::ip::tcp::socket,void()(char*消息, std::字符串主机名,int端口,int 长度)c:\Users\gospo\u 000\Source\Repos\Messenger\Messenger\Messenger\Messenger.cpp 176 4 Messenger

像这样的错误很多:

错误81错误C2780: 'enable_if::value,std:_BindRx(_thiscall _Farg0::*)(\u V0\u t,\u V1\u t,\u V2\u t,\u V3\u t,\u V4\u t),\u Rx,\u V0\u t,\u V1\u t,\u V3\u t,\u V4\u t>,\u Vx0\u Vx1\u t>::类型std::bind(Rx(\u thisgall\u Farg0:*const )(_V0_t,_V1_t,_V2_t,_V3_t,_V4_t),_Vx0_t&,_Vx1_t&):3 论点-8 提供的c:\users\gospo\u 000\source\repos\messenger\messenger\messenger\messenger.cpp 176 1测试仪2

信使

#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));
    };
#包括
#包括
#包括
#包括“Connection.h”
#包括“Message.h”
#包括
使用名称空间std;
使用名称空间boost::asio;
使用boost::asio::ip::tcp;
班级信使
{
//.............................
void receiveCallback(const boost::system::error_code&error,size_t bytes_transfer,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));
    }
}
void Messenger::receiveCallback(const boost::system::error\u code&error,size\u t bytes\u transfer,char*消息,int bufferSize,tcp::socket*socketPtr,void(*onMessageReceivedCallback)(char*消息,字符串主机名,int端口,int长度))
{
如果(错误)
{
字符串connectionId=getConnectionId(socketPtr->remote_endpoint());
连接擦除(connectionId);
coutremote_endpoint().port(),字节_已传输);
socketPtr->async\u接收(
boost::asio::buffer(消息,bufferSize),
boost::bind(&Messenger::receiveCallback,this,_1,_2,message,bufferSize,socketPtr,onMessageReceivedCallback));
}
}

不同之处在于,
std::bind
默认情况下仅使用。将_VARIADIC_MAX macro设置为10,以增加可变模板中的最大arg数。

您能发布足够的代码让我们复制错误吗?或者至少粘贴准确的错误。在
std::bind
line.thx中还有一个额外的
,括号被删除,这不是问题,只是复制“105 IntelliSense:”-你是说IntelliSense错误吗?你试过编译代码吗?错误81错误C2780是一个编译错误,不是吗?我试着编译它,但是有很多编译错误,似乎就是这样的问题。此解决方案有效,谢谢。