小编Tir*_*ias的帖子

没有可用的用户定义转换运算符可以执行此转换,或者无法调用该运算符

我有一个奇怪的错误,我不太明白,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)

c++ lambda conditional-operator std-function

5
推荐指数
1
解决办法
4064
查看次数

标签 统计

c++ ×1

conditional-operator ×1

lambda ×1

std-function ×1