【问题标题】:How to use/manipulate return value from nested boost::bind如何使用/操作嵌套 boost::bind 的返回值
【发布时间】:2011-02-08 16:28:59
【问题描述】:

我有两个功能: 1.A&DataSource(); 2. void DataConsumer( A * );

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

我试过了:

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

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

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

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

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

【问题讨论】:

    标签: c++ boost-bind


    【解决方案1】:

    各位,我刚刚找到了答案,如下所示:

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

    理论上应该是:由于我们稍后调用 DataSource,我们需要一个稍后也使用返回值的函子。

    【讨论】:

    • 如果可以调整Consumer来参考……
    猜你喜欢
    • 2013-10-05
    • 1970-01-01
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    • 2022-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多