C++ VS 2013 中的 11 lambda 回调无法编译

C++ 11 lambda callback in VS 2013 won't compile

本文关键字:回调 编译 lambda VS 2013 中的 C++      更新时间:2023-10-16

我不明白为什么下面的代码不能在VS2013中编译。编译器只是抱怨如下,我不知道如何修复它:

e: \work\justtest\coconsole\coconsole.cpp(37):错误C2664:'booldfsFolder(const wchar_t*,const wchar_t*,std::function&)':无法从转换参数3'main::'到'std::函数&'

bool dfsFolder(__in const wchar_t* folderPath, __in const wchar_t* ext, const std::function<bool(const std::wstring& wsFilePath)>& pFunc)
{
}
int main()
{
        auto path = LR"(F:TODOWNLOAD)";
        auto lambda = [&](const std::wstring& wsFilePath) mutable -> bool
        {
            wcout << wsFilePath << endl;
            return true;
        };
        dfsFolder(path, L"*.jpg", lambda);
}

错误消息似乎与代码不匹配:最后一个参数是std::function<...> const&,而不是错误中所述的std::function<...>&。您的实际代码是否将std::function<...>&参数声明为const