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

标签 c++ c++11 lambda

我不明白为什么我的以下代码无法在 VS 2013 中编译。编译器只是提示如下,我不知道如何修复它:

e:\work\justtest\console\console.cpp(37): error C2664: 'bool dfsFolder(const wchar_t *,const wchar_t *,std::function &)' : cannot convert argument 3 from 'main::' to 'std::function &'

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

关于VS 2013 中的 C++ 11 lambda 回调无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33825254/

相关文章:

python - 如何通过 Python 使用 Selenium 在 invisibility_of_element_located 上等待多个条件

python - Python可以 pickle lambda函数吗?

android - 与 Android 设备交互的桌面应用程序

c++ - 为什么不能将结构作为值作为模板非类型参数传递?

c++ - 为什么字符串文字上的 decltype 不产生数组类型?

c++ - 如何使用 new(std::nothrow) 使构造函数失败?

java8聚合对象转换器

c++ - ShellExecute 不打开默认 Web 浏览器

c++ - 在 C++ 中如何创建一个可以将自身保存为变量的类?

c++ - 错误:数组下标高于 std::vector::insert 的数组边界