There have been other posts regarding initialization of array of nested structs. However, following the given advice elsewhere in Stackoverflow and links to Aggregate Initialization are not helping me resolve an issue.
My context is that I am initializing a number of nested structs in the Vulkan graphics API.
However, in looking at other codes for explanation I ran across the following 'C' initialization (please note that I am adding the defined structs and the code in question)
Vulkan typedefs
typedef union VkClearColorValue {
float float32[4];
int32_t int32[4];
uint32_t uint32[4];
} VkClearColorValue;
typedef struct VkClearDepthStencilValue {
float depth;
uint32_t stencil;
} VkClearDepthStencilValue;
typedef union VkClearValue {
VkClearColorValue color;
VkClearDepthStencilValue depthStencil;
} VkClearValue;
The 'C' code in question
const VkClearValue clear_values[2] = {
[0] = {.color.float32 = {0.2f, 0.2f, 0.2f, 0.2f}},
[1] = {.depthStencil = {demo->depthStencil, 0}},
};
The 'C' represenation is legal in C99 and the latest gcc compiler.
However, as I apply this to C++ I get errors.
Going back to rules for aggregate initialization the 'C' represenation should be legal in C++17. However, on compilation I get errors to the effect: error: expected primary-expression before '.' token
Clearly I am wrong in my assumption. As such, might anyone provide guidance on how to make it legal in C++17.