使用嵌套的lambda时VS 2015出错

时间:2016-06-08 05:50:27

标签: c++ c++11 visual-studio-2015 lambda

这是我的用例的低调版本,在gcc 4.9.3和clang 3.7上编译良好但在VS 2015 Update 2上失败。

#include <functional>
#include <string>
#include<memory>

namespace A {
    using handle = std::function<void(std::string)>;
    void func(std::string, handle) {
    }
}

class B : public std::enable_shared_from_this<B> {

public:
    void func();
};

void B::func()
{
     auto && cast = std::static_pointer_cast<B>(shared_from_this());

     auto const another_variable = [cast]() -> void 
     {
        A::func("hello", [&cast](std::string){ } );
     };
}

int main() {
    return 0;
}

以下是我得到的错误

Error(s):
source_file.cpp(23): error C2440: '<function-style-cast>': cannot convert from 'const std::shared_ptr<_Ty>' to 'B::func::<lambda_4a58826445f3685613b078cf10fc9f7e>::()::<lambda_8290a9c207487c2dc2e26a5b929b4850>'
        with
        [
            _Ty=B
        ]
source_file.cpp(23): note: No constructor could take the source type, or constructor overload resolution was ambiguous
source_file.cpp(23): error C2660: 'A::func': function does not take 1 arguments

有趣的是,它也适用于VS 2013。我错过了一些非常明显的东西吗?

0 个答案:

没有答案