2010-04-16 63 views
1

我有兩個函數: 1. A & DataSource(); 2. void DataConsumer(A *);如何使用/操縱來自嵌套boost :: bind的返回值

我想實現的:使用一條語句將它們組合成一個函子

我曾嘗試:

1.升壓::功能<空隙()> FUNC(升壓::綁定(DataConsumer,&升壓::綁定(數據源)));

肯定它沒有工作,編譯器說,它不能將 '推動:​​: _雙:: bind_t' 到 'A *'

2.的boost ::功能<無效()> func(boost :: bind(DataConsumer,boost :: addressof(boost :: bind(DataSource))));

編譯器說不能轉換從「提升:: _雙:: bind_t」到「A &」

問題參數1:如何從嵌套提升使用的返回值::綁定?或者如果你想使用boost :: lambda :: bind。

回答

1

傢伙,我只是找到了答案,像以下:

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

理論應該是:因爲我們再打數據源,我們需要使用返回值後,以及仿函數。

+0

很明顯! ;-) – DannyT 2010-04-16 07:25:48

+0

如果您可以調整消費者參考... – Potatoswatter 2010-04-16 07:47:16