简体   繁体   中英

Unknown type name C

I know that things have to be defined before they are used, but I am getting an "unknown type name error."

This is my Node definition:

struct Node  {
    position* p;
    struct Node* next;
    struct Node* prev;
};

This is my declaration (on line 96):

Node* hashtable[HashArraySize];

I get this error message:

P1.c:96:1: error: unknown type name ‘Node’
 Node* hashtable[HashArraySize];

Unlike C++ which treats struct tags as new type names, C requires an explicit typedef if you wish to use Node without struct :

typedef struct Node Node;

Alternatively, you could use struct Node in your declaration:

struct Node* hashtable[HashArraySize];

Change Node* hashtable[HashArraySize]; to struct Node* hashtable[HashArraySize];

or

typedef struct Node  {
    position* p;
    struct Node* next;
    struct Node* prev;
} Node;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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