2011-02-08 70 views
4

我見過一些相關的問題,但我仍然感到困惑。有什麼不對的語法:Boost函數和提升lambda

boost::function<int (int)> g = f; 
boost::function<int (int)> g2 = 2*g(boost::lambda::_1); 

我和提升1.35和1.38(這是兩個安裝我已經躺在附近)上GCC 4.3.4,他們都給出了錯誤的變化試了一下

no match for call to '(boost::function<int()(int)>) (const boost::lambda::lambda_functor<boost::lambda::placeholder<1> >&)' 

回答

8

您不能直接調用帶佔位符的函數。您必須登錄use bind

boost::function<int (int)> g2 = 2 * boost::lambda::bind(g, boost::lambda::_1); 

Example

2

我建議你放棄Boost.Lambda,因爲它是過時的。支持C++ 0x的編譯器提供了原生lambda,並且更易於理解。您可以使用4.4或更高版本的GCC,Visual Studio 2010也支持C++ 0x。