【发布时间】:2015-03-15 08:34:26
【问题描述】:
下面的代码很高兴被 GCC 和 Clang 接受,-std=c++14 但在 Visual Studio 2013 中会导致编译错误。
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
auto increasing = [](int lhs, int rhs){return lhs < rhs;};
auto decreasing = [](int lhs, int rhs){return lhs > rhs;};
std::vector<int> v(0, 10);
bool increase = true;
std::sort(v.begin(), v.end(), increase ? increasing : decreasing);
return 0;
}
错误是:
main.cpp(11): error C2446: ':': no conversion from 'main::<lambda_0228ee097b83254cfd8aa5f4015a245b>' to 'main::<lambda_cb3b816d067baa9d4462132ee332363c>'
main.cpp(11): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
我想我的问题是哪个编译器在这里是兼容的,我猜它不是 MSVC,并且标准中是否有明确处理这种情况的部分?
【问题讨论】:
-
请务必提交bug report。
-
@ShafikYaghmour 当我尝试这样做时,我收到“您无权提交此连接的反馈”。所以我想我不允许报告错误。
-
嗯,不久前我创建了我的连接帐户,我认为我不需要做任何特别的事情来报告错误。
-
我为此提交了一个错误报告,希望我有办法使用较新版本的 Visual Studio 进行确认。
-
我有 Visual Studio Community 2017,它显示一个错误(运算符的多个定义可用),但它运行得很好。
标签: c++ visual-c++ c++11 visual-studio-2013 language-lawyer