我正在尝试编写一个函数,该函数将指向我创建的类型的指针作为参数typedef
调用NodeType
。我隐约明白typedef
名字没有联系。我不确定为什么当类型的两个实例NodeType
似乎都在同一个翻译单元中时会出现以下错误。
这是代码:
#include <stdio.h>
int main(){
typedef struct NodeTag{
char* Airport;
NodeTag * Link;
} NodeType;
//Declare print function
void printList(NodeType *);
void printList(NodeType * L){
//set N to point to the first element of L
NodeType * N = L;
//if the list is empty we want it to print ()
printf("( ");
//while we are not at the Link member of the last NodeType
while(N != NULL){
//get the Airport value printed
printf("%s", N->Airport);
//advance N
N= N->Link;
if(N != NULL){
printf(", ");
}
else{
//do nothing
}
}
printf(")");
}
return 0;
}
这是我遇到的错误:
linkedlists.c: In function 'int main()':
linkedlists.c: error: type 'NodeType {aka main()::NodeTag} with no linkage used
to declare function 'void printList(NodeType*) with linkage [-fpermissive]
谢谢你的帮助!