大括号在 VS2019 中初始化继承的结构

Brace initialising an inherited struct in VS2019

我有这个代码片段;

struct x
{
    int thing;
};

struct y : x
{};

//works, but I need to use struct y
struct x test1 { 1 };

//Error
//"Only one level of braces is allowed on an initializer for an object of type "y"
//no suitable constructor exists to convert from "int" to "y"
struct y test { {1} }; 

//Error
//no suitable constructor exists to convert from "int" to "y"
struct y test2 { 1 };

//Error
// no suitable user-defined conversion from "x" to "y" exists
struct y test3 {test1};

//Error
// no suitable user-defined conversion from "x" to "y" exists
struct y test4 = (struct y)test1;

这里有很多关于此类代码的问题。从他们那里,我发现我尝试初始化 struct y test 的方式从 C++17 开始有效,并且在 Visual Studio 2017 的更高版本中有效。我尝试在 Visual Studio 2019,我得到了评论中描述的结果。

有谁知道如何让 VS2019 处理继承结构的初始化?我无法向结构添加构造函数,因为这是对现有代码的抽象,我无法随意更改。

根据 OP 上的评论,VS2019 默认为 C++14。要将项目设置为使用不同的语言标准(在本例中为 C++17),您必须转到项目属性->C/C++->语言->C++语言标准。

VS2017 中存在相同的设置。

感谢对此提供帮助的评论者。