没有用于与联动声明功能联动型 [英] Type with no linkage used to declare function with linkage
问题描述
我试图写一个函数,它作为一个参数指针我与的typedef
名为的NodeType $ C $创建一个类型C>。我依稀明白,
的typedef
名称没有关联。我不知道为什么当键入的NodeType
的两个实例似乎是在同一个翻译单元我会得到下面的错误。
I am trying to write a function that takes as a parameter a pointer to a type I created with typedef
called NodeType
. I dimly understand that typedef
names don't have linkage. I am not sure why I would get the following error when both instances of the type NodeType
appear to be in the same translation unit.
这里是code:
#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]
感谢您的帮助!
推荐答案
您的printList
函数主$ C的主体内定义的$ C>,这是混淆编译器。移动
的printList
的体外主
是这样的:
Your printList
function is defined within the body of main
, which is confusing the compiler. Move printList
outside the body of main
like this:
#include <stdio.h>
typedef struct NodeTag{
char* Airport;
NodeTag * Link;
} NodeType;
//Declare print function
void printList(NodeType *);
int main(){
return 0;
}
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(")");
}
在你这样做,得到它来编译,你需要弄清楚如何以及在哪里调用的printList
从内部主
。
After you've done this and got it to compile, you'll need to figure out how and where to call printList
from within main
.
这篇关于没有用于与联动声明功能联动型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!