有什么不对本的boost ::拉姆达::绑定使用情况如何? [英] What is wrong with this boost::lambda::bind usage?

查看:231
本文介绍了有什么不对本的boost ::拉姆达::绑定使用情况如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个错误在这个code?我不断收到编译错误。基本上我想一个void返回功能连接到具有非void返回类型的信号。
升压版本:版本1.46.1

Is there something wrong in this code? I keep getting compilation errors. Basically I want to connect a void returning function to a signal which has a non void return type. Boost version: Release 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) );
}

我收到以下错误而编译:

I get the following error while compiling:

/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]

感谢。

推荐答案

似乎对升压版本没有问题,编译1.49

Seems to compile with no problem on Boost version 1.49

这篇关于有什么不对本的boost ::拉姆达::绑定使用情况如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆