Boost 函数和 boost lambda
我看到了一些相关的问题,但我仍然感到困惑。这个语法有什么问题:
boost::function<int (int)> g = f;
boost::function<int (int)> g2 = 2*g(boost::lambda::_1);
我在 gcc 4.3.4 上用 boost 1.35 和 1.38(这是我现有的两个安装)尝试过,它们都给出了错误的变体:
no match for call to '(boost::function<int ()(int)>) (const boost::lambda::lambda_functor<boost::lambda::placeholder<1> >&)'
I've seen a few related questions, but am still just puzzled. What's wrong with this syntax:
boost::function<int (int)> g = f;
boost::function<int (int)> g2 = 2*g(boost::lambda::_1);
I've tried it with boost 1.35 and 1.38 (these are the two installations I have lying around) on gcc 4.3.4, and they both give variations of the error:
no match for call to '(boost::function<int ()(int)>) (const boost::lambda::lambda_functor<boost::lambda::placeholder<1> >&)'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能直接使用占位符调用函数。您必须使用
bind< /代码>
。
(示例)
You can't call a function with a placeholder directly. You have to use
bind
.(Example)
我建议您放弃
Boost.Lambda
,因为它已经过时了。支持C++0x的编译器提供原生lambda,更容易理解。您可以使用4.4或更高版本的GCC,Visual Studio 2010还支持C++0x。I suggest you give up
Boost.Lambda
as it’s out of date. The compiler which supports C++0x provides native lambda and is easier to understand. You can use GCC with 4.4 or higher version, Visual Studio 2010 also supports C++0x.