我有一个奇怪的错误,我不太明白,VS2013。这只是我的实际问题的简化,导致了同样的错误。
std::function<bool()> x = (someCondition == true)
? []() { return true; }
: []() { return false; };
Run Code Online (Sandbox Code Playgroud)
VS 编译器错误是:
1>f:\test\cppconsoleapplication\cppconsoleapplication.cpp(497): error C2446: ':' : no conversion from 'main::<lambda_96d01fe3721e46e4e8217a69a07d151b>' to 'main::<lambda_0d38919a9b2aba5caf910d83eac11776>'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Run Code Online (Sandbox Code Playgroud)
IntelliSense 甚至想出了这个神秘的错误消息:
IntelliSense: more than one operator "?" matches these operands:
built-in operator "expression ? pointer : pointer"
built-in operator "expression ? pointer : pointer"
built-in operator "expression ? pointer : pointer" …Run Code Online (Sandbox Code Playgroud)