1

我有两个功能: 1. A & DataSource(); 2. 无效数据消费者(A *);

我想要实现的目标:使用一个语句将它们组装成一个 functor

我努力了:

1. boost::function< void()> func( boost::bind( DataConsumer, & boost::bind( DataSource ) ) );

当然它没有用,编译器说它不能将 'boost::_bi::bind_t ' 转换为 'A *'

2. boost::function<void()> func( boost::bind( DataConsumer, boost::addressof( boost::bind( DataSource ) ) ));

编译器说不能将参数 1 从 'boost::_bi::bind_t' 转换为 'A &'

问题:如何使用嵌套 boost::bind 的返回值?或者如果你想使用 boost::lambda::bind。

4

1 回答 1

1

guys, I just found the answer, like following:

boost::function< void()> func(
        boost::bind( DataConsumer, 
                     boost::bind( boost::addressof< A >, boost::bind< A& >( DataSource ) )
                    )            );

The theory should be: since we call DataSource later, we need a functor that uses the return value later as well.

于 2010-04-16T05:20:13.240 回答