简体   繁体   English

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

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

So the code is saying that List and size is not a structure? 所以代码说List和size不是结构?

typedef struct HashTable{
    int size;
    ListRef **List; 
} hash;

typedef struct hash *hash_ref;

hash_ref *newHash(int size){
    hash_ref *hashed= NULL;
    if(size<1){
        return NULL;
    }
    if( (hashed=malloc(sizeof(hash))) ==NULL){
        return NULL;
    }
    if( (hashed->List=malloc(sizeof(ListRef*)*size)) ==NULL){
        return NULL;
    }
    for(int i=0; i<size; i++){
        hashed->List[i]=NULL;
    }
    hashed->size=size;

    return hashed;
}

Here is my List function 这是我的List功能

typedef struct Node{
    long key;/*book id*/
    ListRef data;
    struct Node* next;
    struct Node* prev;
}NodeType;

typedef NodeType* NodeRef;

typedef struct ListHdr{
    NodeRef first;
    NodeRef last;
    NodeRef current;
    long length;
}ListHdr;

I was wondering whats up with this error? 我想知道这个错误是什么? I forgot to add that ListHdr is changed to ListRef in my List header file.. Which is included in my hashtable module. 我忘了添加ListHdr在我的List头文件中更改为ListRef ..这包含在我的哈希表模块中。

I'm currently trying to create 2 hash tables. 我目前正在尝试创建2个哈希表。 One has table stores 2 long integers. 一个有表存储2个长整数。 The other hashtable takes 1 long integer and a linked list(which has 2 long integers). 另一个哈希表采用1个长整数和一个链表(有2个长整数)。

hash_ref is typedefed to a pointer to hash , so you must declare hashed as hash_ref hashed , not hash_ref *hashed . hash_ref被typedefed为指向 hash指针 ,因此你必须声明hashedhash_ref hashed ,而不是hash_ref *hashed (The latter would effectively create a pointer to pointer to hash .) (后者会有效地创建一个指向hash指针的指针。)

In addition to this, you should omit struct from the typedef that declares hash_ref . 除此之外,您应该从声明hash_ref的typedef中省略struct Currently hash_ref isn't declared to point hash , but to an as-yet-undeclared struct hash . 目前hash_ref未声明为指向hash ,而是声明为尚未声明的struct hash That compiles only because the compiler interprets it as a forward declaration of a struct hash . 这只是因为编译器将其解释为struct hash的前向声明而编译。 This interpretation will cause any code that tries to dereference hash_ref to fail with errors such as "storage size of struct hash unknown". 此解释将导致尝试取消引用hash_ref任何代码失败,并出现诸如“ struct hash unknown”的存储大小之类的错误。

It means you're either calling . 这意味着你要么打电话了. on something that isn't a struct or union OR -> on a pointer that isn't a pointer directly to a struct or union. 在一个不是结构或联合的东西上->在一个不是直接指向结构或联合的指针的指针上。

hash_ref * hashed is a DOUBLE pointer to HashTable. hash_ref * hashed是一个指向HashTable的DOUBLE指针。 A single dereference still gives you a HashTable pointer, which isn't a union or struct. 单个解除引用仍然为您提供HashTable指针,该指针不是联合或结构。

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

相关问题 C-错误:在非结构或联合中请求成员“ ---” - C - error: request for member ‘---’ in something not a structure or union 错误:在非结构或联合C中请求成员“表” - error: request for member ‘table’ in something not a structure or union C C语言错误:请求成员“值”的不是结构或联合 - C language error: request for member ‘value’ in something not a structure or union c-错误:请求成员xxxxxx的内容不是结构或联合 - c - error: request for member xxxxxx in something not a structure or union C中的编译错误:请求成员&#39;____&#39;的形式不是结构或联合 - Compilation Error in C: request for member ‘____’ in something not a structure or union C要求成员*****使用非结构或联合的形式 - C request for member ***** in something not a structure or union C-要求加入非结构或联合的成员 - C - request for member in something not a structure or union “错误:请求成员&#39;clientfd&#39;的方式不是结构或联合” - “error: request for member ‘clientfd’ in something not a structure or union” 错误:在结构或联合中请求成员“ valore” - error: request for member 'valore' in something not a structure or union 错误:在非结构或联合中请求成员“ id” - ERROR:request for member 'id' in something not a structure or union
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM