I want to add a C-style struct to a C++ header and use it in a C function. But this is not working:
struct Vertex {
float Position[2];
float Color[4];
};
struct Square{
Vertex vertices[4];
};
Elsewhere:
float color[4]={rColor, gColor, bColor, alpha};
float halfsize=(float)size/2;
Square square= {
{{halfsize,halfsize},{color[0],color[1],color[2],color[3]}},
{{halfsize,-halfsize},{color[0],color[1],color[2],color[3]}}, //error on this line
{{-halfsize,-halfsize},{color[0],color[1],color[2],color[3]}},
{{-halfsize,halfsize},{color[0],color[1],color[2],color[3]}}
};
Reports “Excess elements in struct initializer” on the second line.
On a related note, is there a more efficient way to pass in the array color to the square set?
You need to add an extra brace for the initializer for
Vertex vertices[4];