下面的代码段在Eclipse不编译:上编译时显示简单的C代码不起作用(typedef的相关)
typedef int Data;
typedef struct node* Node;
typedef struct node {
Data data;
Node next;
};
int main() {
Node n = newNode();
return 0;
}
Node newNode() {
Node newNod;
newNod = malloc(sizeof(struct node));
if(!newNod){
return NULL;
printf("\naa");
}
newNod->data = 3;
return newNod;
}
的一个错误是
error: conflicting types for 'newNode'* (line with newNode() method declaration "Node newNode() {").
我很无能。怎么了?
“方法声明”?听起来像你正在使用C++编译器。无论如何,它不喜欢名称'newNode'用于函数名称和变量名称。 –
@EugeneSh。它被用作函数名称,但没有变量具有该名称... –
@CavanPage正确...误读它。 –