C++ 错误C3861:&x27;initNode';:找不到标识符

C++ 错误C3861:&x27;initNode';:找不到标识符,c++,c,compiler-errors,C++,C,Compiler Errors,我发现以下编译错误: # 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));

我发现以下编译错误:

# 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);
}
错误C3861:“初始化节点”:未找到标识符

# 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);
}
代码如下:

# 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);
}
#包括
#包括“stdafx.h”
#包括
结构节点{
节点*下一步;
int节点值;
};
节点*createList(int值)/*创建链接列表*/
{
node*dummy_node=(node*)malloc(sizeof(node));
虚拟节点->下一步=空;
虚拟节点->节点值=值;
返回虚拟_节点;
}
void addFront(node*head,int num)/*将节点添加到链表的前面*/
{
node*newNode=initNode(num);
newNode->next=NULL;
head->next=newNode;
newNode->nodeValue=num;
}
void deleteFront(node*num)/*从前端删除节点的值*/
{
节点*temp1=num->next;
if(temp1==NULL)
{
printf(“列表为空!!!!”);
}
其他的
{
num->next=temp1->next;
免费(temp1);
}
}
作废销毁列表(节点*列表)/*释放链接列表*/
{
节点*温度;
while(列表->下一步!=NULL)
{
临时=列表;
列表=临时->下一步;
免费(临时);
}
免费(名单);
}
int getValue(节点*列表)/*返回列表的值*/
{
返回((列表->下一步)->节点值);
}
void printList(节点*列表)/*打印链接列表*/
{
节点*当前位置;
对于(currentPosition=list->next;currentPosition->next!=NULL;currentPosition=currentPosition->next)
{`在这里输入代码`
printf(“%d\n”,当前位置->节点值);
}   
printf(“%d\n”,当前位置->节点值);
}
node*initNode(int number)/*创建一个节点*/
{
node*newNode=(node*)malloc(sizeof(node));
新建节点->节点值=编号;
newNode->next=NULL;
返回(newNode);
}

如何修复此错误?

发生此错误是因为
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()
的声明或将其定义移动到首次使用之前

# 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);
}


<代码>看起来像C,但看起来你正在使用C++编译器编译它(使用<代码>节点< /COD>而不是<代码> StReTo结< /Cule>似乎不会导致编译器失败,除非你在帖子中没有报告这些错误)。(使用Visual Studio在源文件上使用
.c
扩展名可以很容易地实现),您不需要强制转换
malloc()
的返回值。请参阅,在问题答案中提供的链接

我将所有函数的签名放在顶部,但现在出现了此错误。”致命错误C1903:无法从以前的错误中恢复;正在停止编译“@OOkhan,不要将其放在结构节点
之前。请解决另一个错误:(“致命错误LNK1169:找到一个或多个乘法定义的符号"如果你发布的文件是头文件,你应该将定义移到
.c
文件中,并在
.h
文件中保留声明。你发布的问题已经得到了回答,你最好用新问题发布一个新问题。更多的人会看到它,并且更容易作为ans提供完整的答案wer和not as comment。我发布的文件不是头文件。它是.cpp文件,我正在另一个.cpp文件中调用这些函数。好的,我将发布我的问题。
# 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);
}