The structure body
is an aggregate that contains data members that in turn are aggregates.
You need to write
body r_plate = { { { 0,0 },{ 5,0 },{ 5,1 },{ 0,1 } } };
That is the structure body contains an array so you have to write
body r_plate = { { ... } };
and each element of the array is an object of the structure type. So you will have
body r_plate = { { { 0,0 },{ 5,0 },{ 5,1 },{ 0,1 } } };
The following initializations will be less readable but correct
body r_plate = { { 0,0,5,0,5,1,0,1 } };
and
body r_plate = { 0,0,5,0,5,1,0,1 };
Here is a demonstration program.
#include <iostream>
typedef struct coordinate{
double x;
double y;
}point;
typedef struct sc_cell{ // single cell
point sc[4];
}cell;
typedef struct sb_body { // for single body
point sb[4];
}body;
using namespace std;
int main()
{
body r_plate = { 0,0,5,0,5,1,0,1 };
for ( const auto &p : r_plate.sb )
{
std::cout << "( " << p.x << ", " << p.y << " ) ";
}
std::cout << '\n';
r_plate = { { 0,0,5,0,5,1,0,1 } };
for ( const auto &p : r_plate.sb )
{
std::cout << "( " << p.x << ", " << p.y << " ) ";
}
std::cout << '\n';
r_plate = { { { 0,0 }, { 5,0 } , { 5,1 }, { 0,1 } } };
for ( const auto &p : r_plate.sb )
{
std::cout << "( " << p.x << ", " << p.y << " ) ";
}
std::cout << '\n';
return 0;
}
The program output is
( 0, 0 ) ( 5, 0 ) ( 5, 1 ) ( 0, 1 )
( 0, 0 ) ( 5, 0 ) ( 5, 1 ) ( 0, 1 )
( 0, 0 ) ( 5, 0 ) ( 5, 1 ) ( 0, 1 )
As for this assignment
r_plate = { { 0,0 },{ 5,0 },{ 5,1 },{ 0,1 } };
then the first inner brace is considered as starting point of the list-initialization of the array. As the structure has only one data member (the array) then all other list-initializations apart the first one do not have corresponding data members of the structure. So the compiler issues an error.