LInkedList在C中的sizeof(Node)中出现奇怪错误



我在sizeof(Node(内的Node的构造函数中收到一个错误,说"不允许使用类型名称",有什么想法吗?谢谢


struct Node {
int data;
Node *next;
};
struct LinkedList {
Node *first;
int size;
};
typedef struct Node Node;
typedef struct LinkedList LinkedList;
//constructor for node
Node* createNode(int data) {
Node * newNode = malloc(sizeOf(Node));
if (data != NULL) {
newNode->data = data;
newNode->next = NULL;
return newNode;
}
return NULL;
}
malloc(sizeOf(Node))

应该是

malloc(sizeof(Node))

我还怀疑还有其他编译器错误;你必须做

struct Node *

而不是

Node *

最新更新