[英]How to make a struct of structs in C++
結構可以包含其他結構嗎?
我想創建一個包含四個其他結構的數組的結構。 這可能嗎? 代碼會是什么樣的?
是的你可以。 例如,此struct S2
包含四個S1
對象的數組:
struct S1 { int a; };
struct S2
{
S1 the_array[4];
};
當然,為什么不呢。
struct foo {
struct {
int a;
char *b;
} bar[4];
} baz;
baz.bar[1].a = 5;
是的,結構可以包含其他結構。 例如:
struct sample {
int i;
char c;
};
struct b {
struct sample first;
struct sample second;
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.