簡體   English   中英

在結構中使用指向結構數組的指針

[英]Using a pointer to an array of structs within a struct

我正在嘗試使用指向另一個結構內的結構數組的指針,並能夠引用不同的結構。 不確定我是否正確執行此操作,因為我無法編譯代碼

typedef struct profile {
    uint32 age;
    uint32 height;
    uint32 weight;
} profile;

typedef struct {
    uint32 number_of_friends;
    profile (*PROFILES)[];
} records;

// Here's how how i'm attempting to reference the above
uint32 age1;
records record1;
...
age1 = record1.PROFILES[0].age;

我得到的錯誤是:錯誤:指向不完整類型'records []'的指針的下標

這里似乎有兩個問題。 我相信,您可以在結構中聲明:

profile** PROFILES;

或者

profile* PROFILES[];

這些具有相同的效果。

然后,在您引用該項目的地方,您應該注意,數組內部是配置文件 *-s,因此您可以像這樣引用它們:

record1.PROFILES[0]->age

還要考慮到最初沒有為 PROFILES 分配空間,您將不得不手動管理該成員的底層存儲。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM