简体   繁体   English

请求成员不是结构或联合错误

[英]request for member in something not a structure or union error

I searched the net for the above error, but people mainly talking about the wrong way of access the fields of the struct (-> vs .). 我在网上搜索了上述错误,但人们主要谈论访问结构字段的错误方式( - > vs。)。 I tried them, but still I keep receiving the same error. 我试过了,但我仍然收到同样的错误。 I have these two structs: 我有这两个结构:

struct Node_ {
    int num;
    G12_t* G12;
}node_t;

struct G12_{
    int level;
    int size;
    G12_t* next;
}G12_t;

When I want to get access to the level field of G12_t in a node_t, I get the above error. 当我想在node_t中访问G12_t的级别字段时,我得到上述错误。 I access to the level field as bellow: 我可以访问以下级别字段:

node_t* pNode;

pNode->G12->level = 0;

It looks like you were attempting to create typedefs for these two types, but you didn't use the typedef keyword. 看起来您正在尝试为这两种类型创建typedef,但您没有使用typedef关键字。 What you did instead was create an instance of struct G12_ called G12_t and an instance of struct Node_ called node_t . 你所做的却是创建一个实例struct G12_称为G12_t和实例struct Node_称为node_t

You need to add the typedef keyword before each one. 您需要在每个之前添加typedef关键字。 Also, you need to define G12_t before node_t , since the latter uses the former, and you can use the G12_t name inside the struct where it's defined. 此外,您还需要定义G12_tnode_t ,因为后者使用前者,你可以使用G12_t名字在那里的定义的结构内。 You need to use the full struct name: 您需要使用完整的结构名称:

typedef struct G12_{
    int level;
    int size;
    struct G12_* next;
}G12_t;

typedef struct Node_ {
    int num;
    G12_t* G12;
}node_t;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM