为什么std :: size()在gcc 8.2.0中不是std的成员 [英] Why std::size() is not a member of std in gcc 8.2.0
问题描述
我正在尝试教自己一些C ++ 17.
I'm trying to teach myself some C++17.
为什么编译器会为以下代码片段引发错误?
Why is the compiler throwing an error for the below code snippet?
#include <iostream>
#include <vector>
#include <iterator>
int main()
{
std::vector<int> v = { 3, 1, 4 };
std::cout << std::size(v) << '\n';
int a[] = { -5, 10, 15 };
std::cout << std::size(a) << '\n';
}
编译器抛出以下错误
manish@Manish-Tummala:~/c_files$ g++ 6.cpp -o - 6.out
6.cpp: In function ‘int main()’:
6.cpp:8:23: error: ‘size’ is not a member of ‘std’
std::cout << std::size(v) << '\n';
^~~~
6.cpp:8:23: note: suggested alternative: ‘size_t’
std::cout << std::size(v) << '\n';
^~~~
size_t
6.cpp:11:23: error: ‘size’ is not a member of ‘std’
std::cout << std::size(a) << '\n';
^~~~
6.cpp:11:23: note: suggested alternative: ‘size_t’
std::cout << std::size(a) << '\n';
^~~~
size_t
推荐答案
有关GCC中的C ++ 17支持,请参考:
For C++17 support in GCC, please refer to:
暂时,默认情况下未启用C ++ 17支持:
For the time being, C++17 support is not enabled by default:
要启用C ++ 17支持,请将命令行参数
-std=c++17
添加到您的g++
命令行中.或者,要启用除C ++ 17功能之外的GNU扩展,请添加-std=gnu++17
.
To enable C++17 support, add the command-line parameter
-std=c++17
to yourg++
command line. Or, to enable GNU extensions in addition to C++17 features, add-std=gnu++17
.
目前,用于GCC的C ++ 17 ABI尚未完成.这意味着今天以C ++ 17模式构建的程序可能无法链接到同样以C ++ 17模式编译的过去或将来的二进制文件(或在运行时崩溃).稳定的ABI可确保跨编译器版本实现这种互操作性.
At present, the C++17 ABI for GCC has not been finalized yet. This means that programs built today in C++17 mode may not be able to link against past or future binaries also compiled in C++17 mode (or crash at run time). A stable ABI ensures such interoperability across compiler versions.
一旦ABI最终确定,GCC的未来版本将默认启用C ++ 17模式.
Once the ABI is final, a future version of GCC will enable C++17 mode by default.
这篇关于为什么std :: size()在gcc 8.2.0中不是std的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!