Technically it works like you wrote it, but struct word is unnecessary on members (actually generates warning but works.)
struct Force {
float X[10];
float Y[10];
float Z[10];
};
struct Measurement {
char serial_number[30];
Force F1;
Force F2;
};
Then in function use like this:
Measurement somevar;
somevar.F1.Y = 999;
Now the proper way to do this (and save stack) is to use pointers.
struct Measurement {
char serial_number[30];
Force* F1;
Force* F2;
};
And then:
Measurement* m = new Measurement;
if (m) {
m->F1 = new Force;
m->F2 = new Force;
}
After using you have to delete all pointers to avoid memory leaks:
delete m->F1;
delete m->F2;
delete m;
There is another approach. Using:
struct Force {
float X[10];
float Y[10];
float Z[10];
};
struct Measurement {
char serial_number[30];
Force F1;
Force F2;
};
You can allocate with malloc some amount of memory and treat it as struct (did not have time to test it, but I use that approach many times).
Measurement* m = (Measurement*)malloc(sizeof( size in bytes of both structs ));
// zero memory on m pointer
// after use
free(m);
That's all.