【发布时间】:2012-04-20 11:02:27
【问题描述】:
我在 MSVC2010 中遇到了 lambda 问题。
编译成功:
auto f1 = []() { };
boost::function<void()> a = f1;
但它带来了错误C2440:
auto f2 = []()
{
auto f3 = []() { };
boost::function<void()> b = f3;
};
错误 C2440:
'initializing' : cannot convert from 'int' to 'boost::function<Signature>'
with
[
Signature=void (void)
]
No constructor could take the source type, or constructor overload resolution was ambiguous
为什么?它在 GCC4.6 中有效吗?
【问题讨论】:
-
你为什么使用 boost::function 而不是 std::function?
-
因为我项目的依赖库使用了 boost::function。它可以与 std::function 一起使用吗?
-
我使用 vc10 测试了您的代码,但改用了
std::function。它编译得很好。那么,使用 clang 3.2 和 gcc 4.6.2 的代码也是如此。我没有方便的 boost 库,所以我无法评论您的确切问题。 HTH!
标签: c++ visual-c++ c++11