错误C3861:'initNode':标识符找不到 [英] error C3861: 'initNode': identifier not found

查看:280
本文介绍了错误C3861:'initNode':标识符找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下编译错误:

错误C3861:'initNode':标识符找不到

error C3861: 'initNode': identifier not found"

下面是code:

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

如何解决这个问题?

How to fix this error ?

推荐答案

错误发生,因为 initNode()它被调用之前是不可见的。
要纠正地方 initNode的声明(),或它的首次使用前移到它的​​定义,以

The error is occurring because initNode() is not visible before it is called. To correct place a declaration for initNode(), or move its definition, to before its first use.

在code看起来像C,但它似乎使用的是C ++编译器来编译它(如使用节点而不是结构节点似乎不是导致编译失败,除非你没有报告在您的文章,这些错误)。如果您使用的C编译器(可通过其与Visual Studio的源文件中的 .C 扩展可以轻松实现),你并不需要转换的返回值的malloc()。间看到不兼容性
ISO C和ISO C ++
,一发现提供了问题的答案<一个链接href=\"http://stackoverflow.com/questions/861517/what-issues-can-i-expect-compiling-c-$c$c-with-a-c-compiler\">What问题可能我预计编译C code与C ++编译器?

The code looks like C but it appears you are using a C++ compiler to compile it (as use of node and not struct node appears to not be causing the compiler to fail, unless you have not reported these errors in your post). If you use a C compiler (which can be easily achieved by having a .c extension on your source file with Visual Studio), you do not need to cast the return value of malloc(). See Incompatibilities Between ISO C and ISO C++ , a link a found provided on answer to the question What issues can I expect compiling C code with a C++ compiler?

这篇关于错误C3861:'initNode':标识符找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆