【问题标题】:Why can't I compile structured bindings?为什么我不能编译结构化绑定?
【发布时间】:2018-09-23 11:17:16
【问题描述】:

我试图编译这段代码(在文件 test.cpp 中)

#include<tuple>

int main(){
  auto [c,d] = make_tuple(3.1,2.3);
}

使用 g++ -std=c++17 test.cpp -o test , 也 clang++ -std=c++1z test.cpp -o test 两者都会打印错误消息:

test.cpp: In function ‘int main()’:
test.cpp:3:7: error: expected unqualified-id before ‘[’ token
auto [c,d] = make_tuple(3.1,2.3);

使用 g++ (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 和 clang 版本 3.8.0-2ubuntu4 (使用 Ubuntu 16.04.09) 我错过了什么?

【问题讨论】:

  • 使用更新的版本

标签: c++ g++ c++17 clang++


【解决方案1】:

来自GCC官网:

  • gcc 版本 7 支持结构化绑定

来自clang官网:

  • 第 4 版支持结构化绑定。

以下链接提供了对新 C++ 功能的编译器支持。 https://en.cppreference.com/w/cpp/compiler_support

【讨论】:

    猜你喜欢
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多