c++ - 我们在 C++17 中有自动数组吗?

标签 c++ c++17

考虑以下代码:

auto numbers = {1, 2, 3, 4};    // 'numbers' is an std::intializer_list<int>
auto num_array[] = {1, 2, 3, 4} // error -> declared as an array of 'auto'

为什么会有这个限制?

最佳答案

使用 C++17 和 class template argument deduction ,这很好用:

#include <array>
std::array arr{1, 2, 3, 4};
int i = arr.size();  // 4

关于c++ - 我们在 C++17 中有自动数组吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50840908/

相关文章:

c++ - 为什么递归 constexpr 模板值不编译?

c++ - SFINAE 在 std::enable_if 参数中

c++ - 如何在 C++ 中的文件列表中逐个文件打开文件?

C++ 问题 : Cannot allocate an object of abstract type, 但为什么呢?

C++ 字符串到字符串的转换

c++ - 指向非指针编译错误的唯一指针

c++ - "constexpr if"不支持别名使用?

c++ - 在angstrom上编译c/c++程序

c++ - printf 黑客的格式字符串

c++ - C++11 和 C++17 基于范围的 For 循环是否可以迭代到特定位置而不是 map 的整个范围?