我收到以下编译错误:
错误 C3861:'initNode':找不到标识符”
下面是代码:
# include <conio.h>
# include "stdafx.h"
# include <stdlib.h>
struct node{
node * next;
int nodeValue;
};
node*createList (int value) /*Creates a Linked-List*/
{
node *dummy_node = (node*) malloc(sizeof (node));
dummy_node->next=NULL;
dummy_node->nodeValue = value;
return dummy_node;
}
void addFront (node *head, int num ) /*Adds node to the front of Linked-List*/
{
node*newNode = initNode(num);
newNode->next = NULL;
head->next=newNode;
newNode->nodeValue=num;
}
void deleteFront(node*num) /*Deletes the value of the node from the front*/
{
node*temp1=num->next;
if (temp1== NULL)
{
printf("List is EMPTY!!!!");
}
else
{
num->next=temp1->next;
free(temp1);
}
}
void destroyList(node *list) /*Frees the linked list*/
{
node*temp;
while (list->next!= NULL)
{
temp=list;
list=temp->next;
free(temp);
}
free(list);
}
int getValue(node *list) /*Returns the value of the list*/
{
return((list->next)->nodeValue);
}
void printList(node *list) /*Prints the Linked-List*/
{
node*currentPosition;
for (currentPosition=list->next; currentPosition->next!=NULL; currentPosition=currentPosition->next)
{`enter code here`
printf("%d \n",currentPosition->nodeValue);
}
printf("%d \n",currentPosition->nodeValue);
}
node*initNode(int number) /*Creates a node*/
{
node*newNode=(node*) malloc(sizeof (node));
newNode->nodeValue=number;
newNode->next=NULL;
return(newNode);
}
如何修复此错误?
发生错误的原因是initNode()
在调用之前是不可见的。
更正声明的位置initNode()
,或将其定义移至首次使用之前。
该代码看起来像 C,但似乎您正在使用 C++ 编译器来编译它(如使用node
并不是struct node
似乎不会导致编译器失败,除非您没有在帖子中报告这些错误)。如果您使用 C 编译器(可以通过拥有.c
使用 Visual Studio 在源文件上添加扩展名),您不需要转换返回值malloc()
. See 之间的不兼容性
ISO C 和 ISO C++,在问题答案中找到的链接使用 C++ 编译器编译 C 代码会出现哪些问题?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)