【发布时间】:2020-07-08 10:57:07
【问题描述】:
当我尝试将结构指针传递给函数时出现此错误,这是什么意思,为什么我不能传递 struct*?
我有多个与此类似的函数都返回相同的错误。
我已经尝试过Passing struct pointer to function in c 中提到的解决方案。但是会打印相同的错误。我在下面分别为带有和不带有 soln 的两个程序附加了链接
**ERROR**:</p>
$ gcc -o class -Wall -Werror -Wwrite-strings -std=gnu99 -ggdb3 classroster2.c
<p >classroster2.c:15:23:
error: **'struct node' declared inside parameter list will not be visible outside of this definition or declaration [-Werror]**
15 | void enterName(struct node* xptr);
classroster2.c:57:6: **error: conflicting types for 'enterName'**
57 | void enterName(struct node* xptr){
classroster2.c:15:6: **note: previous declaration of 'enterName' was here**
15 | void enterName(struct node* xptr);
struct student{
size_t noClass;
char **classTaken;
};
struct node{
struct student* details;
struct node *next;
char *name;
};
功能在这里
void enterName(struct node* xptr){
printf("\nEnter the name of Student(%d)(max 12)= ",studentNo+1);
xptr->name=malloc(MAX_LENGTH);
alloCheck(xptr->name);
scanCheck(scanf("%s", xptr->name));
studentNames[studentNo] = xptr->name;
studentNo++;
}
调用函数
struct node * studenti =NULL;
init(studenti);
//studentname
enterName(studenti);
PS:完整的代码可以在这里找到(sry我还在学习git)
【问题讨论】: