【问题标题】:What is wrong with this boost::lambda::bind usage?这个 boost::lambda::bind 用法有什么问题?
【发布时间】:2012-08-13 15:25:32
【问题描述】:

这段代码有问题吗?我不断收到编译错误。基本上我想将一个 void 返回函数连接到一个具有非 void 返回类型的信号。 Boost 版本:发布 1.46.1

#include <boost/signals2.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/lambda/lambda.hpp>
using namespace boost::signals2;

void func()
{
  printf("Func called!");
}

main()
{
  signal<int(int)> sig;
  sig.connect( (boost::lambda::bind(func),  1) );
}

编译时出现以下错误:

/opt/include/boost/signals2/detail/slot_template.hpp: In member function ‘void boost::signals2::slot1<R, T1, SlotFunction>::init_slot_function(const F&) [with F = int, R = int, T1 = int, SlotFunction = boost::function<int(int)>]’:
/opt/include/boost/signals2/detail/slot_template.hpp:81:9:   instantiated from ‘boost::signals2::slot1<R, T1, SlotFunction>::slot1(const F&) [with F = int, R = int, T1 = int, SlotFunction = boost::function<int(int)>]’
hello-world-example.cpp:13:51:   instantiated from here
/opt/include/boost/signals2/detail/slot_template.hpp:156:9: error: invalid conversion from ‘int’ to ‘boost::function<int(int)>::clear_type*’ [-fpermissive]
/opt/include/boost/function/function_template.hpp:1110:14: error:   initializing argument 1 of ‘boost::function<R(T0)>::self_type& boost::function<R(T0)>::operator=(boost::function<R(T0)>::clear_type*) [with R = int, T0 = int, boost::function<R(T0)>::self_type = boost::function<int(int)>]’ [-fpermissive]

谢谢。

【问题讨论】:

    标签: boost boost-bind boost-function boost-lambda boost-signals2


    【解决方案1】:

    似乎在 Boost 版本 1.49 上编译没有问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-17
      相关资源
      最近更新 更多