【问题标题】:Error: request for member ‘check’ in something not a structure or union错误:请求成员“检查”不是结构或联合
【发布时间】:2015-05-12 17:26:19
【问题描述】:

我正在尝试在我的代码中实现这个功能

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); }

它给了我这个错误:

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

还有下一个

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

我使用的结构是:

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;

【问题讨论】:

    标签: c


    【解决方案1】:
    typedef struct node{Check check ;struct node *next; } *link;
    

    所以,link 是指向 node 的指针。

    link *temp;
    

    temp 是指向link 的指针,或指向节点的指针。

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

    这也可以写成(*temp).check.refc(*temp) 是一个指向节点的指针,但您使用为结构和联合保留的 . 访问它。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多