绑定重载函数

时间:2014-02-15 02:31:31

标签: c++ boost

此代码已开发并最初与boost 1.48一起使用。由于更新为boost 1.52,因此拒绝编译。

boost::signals2::signal<void (uint32_t)> foo;
boost::shared_ptr<boost::circular_buffer<uint32_t>> _foo_buffer = new boost::circular_buffer<uint32_t>(32);
_foo.connect(boost::bind(&boost::circular_buffer<uint32_t>::push_front, _foo_buffer, _1));

目标是让foo(42)42放在循环缓冲区的前面。

我的编译错误是No matching function for call to 'bind',有一堆Candidate template ignored: couldn't infer template argument 'R'和类似的模板错误。

我怀疑问题是在我使用的提升版本之间,push_front的定义已从

更改
void push_front(const_reference item = value_type());

三个定义

void push_front(param_value_type);
void push_front(rvalue_type);
void push_front();

它使我的编译器感到困惑。

我非常感谢一些可以使用新升级库的连接表达式的语法帮助。感谢

1 个答案:

答案 0 :(得分:1)

假设你有两个功能

void foo( int ) {}
void foo( double* ) {}

然后你不能只写&foo,因为那样会不明确。

但您可以使用static_cast来建立只有一个候选人可能的背景,因此:

static_cast<void(*)(int)>( &foo )

,它为您提供第一个的地址,并为第二个提供同样的地址。


说,看起来你可以通过使用C ++ lambda函数而不是bind来简化事情(对于C ++ 03编译器或者定义你自己的函数)。

相关问题