考虑以下代码:
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/