I'm feeling really dumb right now, because it's been almost 2 years since I've done any C/C++, while my job has had me writing Java for that time and now I'm having trouble remembering even simple stuff, or else I remember the way to do it in Java instead... I have some C code that I'm trying to use in C++, but I'm having issues with the few things that aren't directly compatible, like struct initialization. The struct definition looks like this:
typedef struct
{
struct
{
uint8_t StreamingInterfaceNumber;
USB_Endpoint_Table_t DataINEndpoint;
USB_Endpoint_Table_t DataOUTEndpoint;
} Config;
struct
{
uint8_t RESERVED;
} State;
} USB_ClassInfo_MIDI_Device_t;
The original C-style initialization looks like this:
USB_ClassInfo_MIDI_Device_t MIDI_Interface =
{
.Config =
{
.StreamingInterfaceNumber = 1,
.DataINEndpoint =
{
.Address = MIDI_STREAM_IN_EPNUM,
.Size = MIDI_STREAM_EPSIZE,
.Banks = 1,
},
.DataOUTEndpoint =
{
.Address = MIDI_STREAM_OUT_EPNUM,
.Size = MIDI_STREAM_EPSIZE,
.Banks = 1,
},
},
};
Which obviously doesn't work in C++. What's the best way to initialize a struct in C++? I don't want to modify the definition, since it exists in a code library that I don't maintain, and would like to leave alone, so I'd rather not add a constructor. I like the style suggested here https://stackoverflow.com/a/6182627/1609411 but I don't know what the syntax is supposed to look like for the nested structs.