boost::function和boost::bind相关问题...

NewbieProgramer 2012-08-13 09:34:43
绑定代码:

boost::shared_ptr<string> send_buffer(new string(encode(*_msg)));

boost::function<void(void)>send_call_back = boost::bind(
&Connection::async_send_msg_call_back,
this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred,
send_buffer
);


回调函数原型:
void Connection::async_send_msg_call_back(
boost::system::error_code& ec,
std::size_t bytes_transferred,
boost::shared_ptr<string> send_buffer)
{

}
[/code]

以上这个是模仿asio下的async_read_some写的,它的源码注释中有(basic_stream_socket.hpp)
@code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes written.
* ); @endcode

编译出错....
一大堆模板报错...你们不想看的...

1>------ 已启动生成: 项目: Slave, 配置: Debug Win32 ------
1> Connection.cpp
1> Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
1> - add -D_WIN32_WINNT=0x0501 to the compiler command line; or
1> - add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.
1> Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2784: “result_traits<R,F>::type boost::_bi::list0::operator [](const boost::_bi::bind_t<R,F,L> &) const”: 未能从“重载函数类型”为“重载函数类型”推导 模板 参数
1> d:\boost_1_50_0\boost\bind\bind.hpp(178) : 参见“boost::_bi::list0::operator []”的声明
1> d:\boost_1_50_0\boost\bind\bind_template.hpp(20): 参见对正在编译的函数 模板 实例化“void boost::_bi::list4<A1,A2,A3,A4>::operator ()<F,boost::_bi::list0>(boost::_bi::type<T>,F &,A &,int)”的引用
1> with
1> [
1> A1=boost::_bi::value<Connection *>,
1> A2=boost::arg<1>,
1> A3=boost::arg<2>,
1> A4=boost::_bi::value<boost::shared_ptr<std::string>>,
1> F=boost::_mfi::mf3<void,Connection,boost::system::error_code &,size_t,boost::shared_ptr<std::string>>,
1> T=void,
1> A=boost::_bi::list0
1> ]
1> d:\boost_1_50_0\boost\bind\bind_template.hpp(18): 编译类 模板 成员函数“void boost::_bi::bind_t<R,F,L>::operator ()(void)”时
1> with
1> [
1> R=void,
1> F=boost::_mfi::mf3<void,Connection,boost::system::error_code &,size_t,boost::shared_ptr<std::string>>,
1> L=boost::_bi::list4<boost::_bi::value<Connection *>,boost::arg<1>,boost::arg<2>,boost::_bi::value<boost::shared_ptr<std::string>>>
1> ]
1> d:\scn\slave\slave\connection.cpp(29): 参见对正在编译的类 模板 实例化“boost::_bi::bind_t<R,F,L>”的引用
1> with
1> [
1> R=void,
1> F=boost::_mfi::mf3<void,Connection,boost::system::error_code &,size_t,boost::shared_ptr<std::string>>,
1> L=boost::_bi::list4<boost::_bi::value<Connection *>,boost::arg<1>,boost::arg<2>,boost::_bi::value<boost::shared_ptr<std::string>>>
1> ]
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2784: “result_traits<R,F>::type boost::_bi::list0::operator [](boost::_bi::bind_t<R,F,L> &) const”: 未能从“重载函数类型”为“重载函数类型”推导 模板 参数
1> d:\boost_1_50_0\boost\bind\bind.hpp(176) : 参见“boost::_bi::list0::operator []”的声明
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2784: “T &boost::_bi::list0::operator [](const boost::reference_wrapper<T> &) const”: 未能从“重载函数类型”为“重载函数类型”推导 模板 参数
1> d:\boost_1_50_0\boost\bind\bind.hpp(174) : 参见“boost::_bi::list0::operator []”的声明
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2784: “const T &boost::_bi::list0::operator [](const boost::_bi::value<T> &) const”: 未能从“重载函数类型”为“重载函数类型”推导 模板 参数
1> d:\boost_1_50_0\boost\bind\bind.hpp(172) : 参见“boost::_bi::list0::operator []”的声明
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2784: “T &boost::_bi::list0::operator [](boost::_bi::value<T> &) const”: 未能从“重载函数类型”为“重载函数类型”推导 模板 参数
1> d:\boost_1_50_0\boost\bind\bind.hpp(170) : 参见“boost::_bi::list0::operator []”的声明
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2676: 二进制“[”:“boost::_bi::list0”不定义该运算符或到预定义运算符可接收的类型的转换
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2784: “result_traits<R,F>::type boost::_bi::list0::operator [](const boost::_bi::bind_t<R,F,L> &) const”: 未能从“重载函数类型”为“重载函数类型”推导 模板 参数
1> d:\boost_1_50_0\boost\bind\bind.hpp(178) : 参见“boost::_bi::list0::operator []”的声明
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2784: “result_traits<R,F>::type boost::_bi::list0::operator [](boost::_bi::bind_t<R,F,L> &) const”: 未能从“重载函数类型”为“重载函数类型”推导 模板 参数
1> d:\boost_1_50_0\boost\bind\bind.hpp(176) : 参见“boost::_bi::list0::operator []”的声明
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2784: “T &boost::_bi::list0::operator [](const boost::reference_wrapper<T> &) const”: 未能从“重载函数类型”为“重载函数类型”推导 模板 参数
1> d:\boost_1_50_0\boost\bind\bind.hpp(174) : 参见“boost::_bi::list0::operator []”的声明
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2784: “const T &boost::_bi::list0::operator [](const boost::_bi::value<T> &) const”: 未能从“重载函数类型”为“重载函数类型”推导 模板 参数
1> d:\boost_1_50_0\boost\bind\bind.hpp(172) : 参见“boost::_bi::list0::operator []”的声明
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2784: “T &boost::_bi::list0::operator [](boost::_bi::value<T> &) const”: 未能从“重载函数类型”为“重载函数类型”推导 模板 参数
1> d:\boost_1_50_0\boost\bind\bind.hpp(170) : 参见“boost::_bi::list0::operator []”的声明
1>d:\boost_1_50_0\boost\bind\bind.hpp(457): error C2676: 二进制“[”:“boost::_bi::list0”不定义该运算符或到预定义运算符可接收的类型的转换
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
...全文
444 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
litterbug23 2013-08-06
  • 打赏
  • 举报
回复
boost::function<void()>
  • 打赏
  • 举报
回复
成员函数得先mem_fn吧
预备-唱 2012-11-18
  • 打赏
  • 举报
回复
引用 楼主 NewbieProgramer 的回复:
本帖最后由 NewbieProgramer 于 2012-08-13 09:55:38 编辑 绑定代码: C/C++ code?12345678910boost::shared_ptr<string> send_buffer(new string(encode(*_msg))); boost::function<void(void……
我也遇到了相同的问题,但是不是参数声明不匹配的问题,function有这种类似的用法,我觉得可能是占位符的某些问题导致的。
退学者的游戏 2012-08-15
  • 打赏
  • 举报
回复
参数不匹配!
eatsweetpotato 2012-08-15
  • 打赏
  • 举报
回复
boost::function<void(void)>send_call_back;

你是不是忘记函数参数了
appelez_moi 2012-08-15
  • 打赏
  • 举报
回复
boost::function<void(void)> send_call_back定义的同你实际bind的参数对不上。。。

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧