I have this code fragment;
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;
There are many questions on here regarding such code. From them, I discovered that the way I'm trying to initialise struct y test
is valid from C++17, and works in later versions of Visual Studio 2017. I've tried to use this in Visual Studio 2019 and I get the results described in the comments.
Does anyone know how I can get VS2019 to handle initialisation of an inherited struct? I can't add a constructor to the struct because this is an abstraction of existing code I can't arbitrarily change.