[英]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
的指针 ,因此你必须声明hashed
为hash_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.