O'Skywalker
O'Skywalker

Reputation: 701

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

I can't understand why my following code can't compile in VS 2013. The compiler just complains as follows, and I don't know how to fix it:

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);
}

Upvotes: 0

Views: 229

Answers (1)

Dietmar K&#252;hl
Dietmar K&#252;hl

Reputation: 153810

The error message doesn't seem to match the code: the last argument is a std::function<...> const& not a std::function<...>& as stated in the error. Does your actual code declare the std::function<...>& parameter as const?

Upvotes: 1

Related Questions