错误:请求成员'检查'的东西不是结构或联合

时间:2022-02-02 21:19:26

I am trying to implement this function in my code

我试图在我的代码中实现此功能

Check QUEUEdelete_check(Q q, int refc){

 link *temp;
 *temp = q->head;
 if(temp->check.refc == refc)
    q->head = temp->next;
    free(temp);
    return temp->check;

 while(temp->next != NULL){
    if (temp->next->check.refc == refc){
        temp->next = temp->next->next;
        if(temp->next == NULL)
            q->tail = temp;
    free(temp->next);
    return temp->check;
    }
    temp = temp->next;
 }
 printf("Cheque %ld does not exist", refc); }

It gives me this error:

它给了我这个错误:

Queue.c: In function ‘QUEUEdelete_check’: Queue.c:49:12: error: request for member ‘check’ in something not a structure or union

Queue.c:在函数'QUEUEdelete_check'中:Queue.c:49:12:错误:请求成员'检查'的东西不是结构或联合

and also for the next

还有下一个

Queue.c:50:23: error: request for member ‘next’ in something not a structure or union q->head = temp->next; if(temp->check.refc == refc)

Queue.c:50:23:错误:请求成员'next'不是结构或联合q-> head = temp-> next; if(temp-> check.refc == refc)

The structs I'm using are:

我正在使用的结构是:

typedef struct queue{ link head; link tail;} *Q; 
typedef struct node{Check check ;struct node *next; } *link;
typedef struct Check{long int amount, refe, refb, refc;}Check;

1 个解决方案

#1


typedef struct node{Check check ;struct node *next; } *link;

So, link is a pointer to node.

因此,link是指向节点的指针。

link *temp;

temp is a pointer to link, or pointer to pointer to node.

temp是指向链接的指针,或指向节点的指针。

 if(temp->check.refc == refc)

This can also be written as (*temp).check.refc. (*temp) is a pointer to node, but you are accessing it with . which is reserved for structs and unions.

这也可以写成(* temp).check.refc。 (* temp)是指向节点的指针,但您正在使用它来访问它。这是为结构和工会保留的。

You need to either to (*temp)->check.refc or (much preferred) refactor your code to not use those pesky double pointers.

您需要(* temp) - > check.refc或(更喜欢)重构您的代码以不使用那些讨厌的双指针。

#1


typedef struct node{Check check ;struct node *next; } *link;

So, link is a pointer to node.

因此,link是指向节点的指针。

link *temp;

temp is a pointer to link, or pointer to pointer to node.

temp是指向链接的指针,或指向节点的指针。

 if(temp->check.refc == refc)

This can also be written as (*temp).check.refc. (*temp) is a pointer to node, but you are accessing it with . which is reserved for structs and unions.

这也可以写成(* temp).check.refc。 (* temp)是指向节点的指针,但您正在使用它来访问它。这是为结构和工会保留的。

You need to either to (*temp)->check.refc or (much preferred) refactor your code to not use those pesky double pointers.

您需要(* temp) - > check.refc或(更喜欢)重构您的代码以不使用那些讨厌的双指针。