【发布时间】:2021-07-14 02:56:27
【问题描述】:
在 C++17 中,为什么这种初始化 std::array 的方式不起作用?
#include <array>
#include <string_view>
class myClass {
private:
struct myStruct {
const std::string_view a;
const int b;
const int c;
};
static inline constexpr std::array<myStruct, 2> myArray = {{"", 0, 0},{"", 0, 0}};
};
我认为 CWG 1270 中的更改涵盖了这种风格。但是,我发现使其发挥作用的唯一方法是:
static inline constexpr std::array<myStruct, 2> myArray = {{{"", 0, 0},{"", 0, 0}}};
或
static inline constexpr std::array<myStruct, 2> myArray = {myStruct{"", 0, 0},myStruct{"", 0, 0}};
【问题讨论】:
-
建议您也将遇到的错误添加到问题中,这样我就可以确定(或者可以确定我们可以使用不同的编译器发出不同的错误消息)我们都在寻找同一个问题。
-
山姆只是朝着我前进的方向前进。他只是进一步简化了问题。 I stopped at the struct and the array
标签: c++