C++0x λ + 提升::函数故障

C++0x lambda + boost::function trouble

本文关键字:函数 故障 提升 C++0x      更新时间:2023-10-16

我在MSVC2010中遇到了lambdas的问题。

它已成功编译:

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中有效吗?

可能是 MSVC 中的一个错误(错误消息似乎非常可疑)。它适用于 GCC 4.7。