gpt4 book ai didi

c++ - 为什么我不能编译结构化绑定(bind)?

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:21:06 26 4
gpt4 key购买 nike

我试图编译这段代码(在文件 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和铛版本 3.8.0-2ubuntu4(使用 Ubuntu 16.04.09)我错过了什么?

最佳答案

来自GCC官网:

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

来自clang官网:

  • 版本 4 支持结构化绑定(bind)。

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

关于c++ - 为什么我不能编译结构化绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49811182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com