0

我的代码中出现这些错误。我确信这些只是因为某个错误,但我找不到它。请帮我!

2010\projects\firstnamelastname\firstnamelastname\testing.cpp(15): error C2065: 'node' : undeclared identifier
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(15): error C2065: 'linked_list2' : undeclared identifier
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(26): error C2065: 'linked_list2' : undeclared identifier
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(29): error C2065: 'linked_list2' : undeclared identifier
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(29): error C3861: 'createQueue': identifier not found
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(35): error C2065: 'linked_list2' : undeclared identifier
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(38): error C2065: 'linked_list2' : undeclared identifier
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(38): error C3861: 'addFront': identifier not found
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(45): error C2065: 'linked_list2' : undeclared identifier
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(45): error C2065: 'linked_list2' : undeclared identifier
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(45): error C3861: 'dQueue': identifier not found
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(48): error C2065: 'linked_list2' : undeclared identifier
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(48): error C3861: 'destroyList': identifier not found
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(52): error C2065: 'linked_list2' : undeclared identifier
1>c:\users\omer\documents\visual studio 2010\projects\firstnamelastname\firstnamelastname\testing.cpp(52): error C3861: 'printList': identifier not found

以下是三个文件 文件 1 >> testing.cpp

//#include<stdio.h>
#include<stdlib.h>
#include "queue.h"
#include "linklist.h"
#include"stdafx.h"

int main(void)
{   
    int x,n;
    int number;
    int i;

    node *linked_list2= NULL;


        while (1) 
        {           
            printf("1.)To create Queue\n2.)To nQueue\n3.)To dQueue\n4.)To Destroy Queue\n5.)To Print The Queue\n6.)Exit Program\nPrint Your Choice: ");
            scanf("%d",&n);

            switch (n) /*Switch statement for testing of different functions*/
            {
                case 1:
                    if(linked_list2 == NULL){
                        printf("Enter Value Please\n");
                        scanf("%d",&number);
                        linked_list2=createQueue(number);
                    }
                    else
                        printf("Queue already created\n.");
                break;
                case 2:
                    if(linked_list2 != NULL){
                        printf("Give a no. to add: ");
                        scanf("%d",&number);
                        addFront(linked_list2,number);
                    }
                    else
                        printf("Create Link List First\n.");

                break;
                case 3:
                    linked_list2=dQueue(linked_list2);
                break;
                case 4:
                    destroyList(linked_list2);
                printf("List is Empty!! So Exiting Program! Bye!!\n");   /*Exits program after the list is emptied*/
                break;
                case 5:
                printList(linked_list2);
                break;
                case 6:
                printf("Exiting Program");
                return 0;
                break;
                default:
                printf("Wrong Input!!! Please Input Again: ");        /*asks to input the choice again if its incorrect*/
                scanf("%d",&n);

            }
        }

    return 0;
}

文件 2 >> queue.h

#include"linklist.h"

node * dQueue(node *num)   /*Deletes the value of the node from the front*/
{
    //num = num->next;  
    return (num->next);
}


void nQueue (node *head, int num ) /*Adds node to the front of Linked-List*/
{
    addFront(head,num);
}

node* createQueue(int val){

    return createList(val);
}

文件 3 >> 链接列表.h

struct node{
    node * next;
    int nodeValue;
};

node* initNode(int number);
node* createList (int value);
void addFront (node *head, int num );
void deleteFront(node*num);
void destroyList(node *list);
int getValue(node *list);
void printList(node *list);

我在linklist.cpp.

4

4 回答 4

5

在 C 中,声明struct foo不会引入名为foo.

你需要:

  • struct node不管你说什么node
  • 或添加typedef struct node node.
于 2012-10-05T14:03:36.403 回答
1

使用 typedef struct 而不仅仅是 struct :

typedef struct _node{
  node * next;
  int nodeValue;
}node;
于 2012-10-05T14:08:17.103 回答
0
typedef struct _node{
    struct _node * next;
    int nodeValue;
} node;
于 2012-10-05T14:05:18.930 回答
0
error C2065: 'node' : undeclared identifier

正如它所说:标识符未声明。与 C++ 不同,C 对structs 和其他东西有单独的命名空间,所以使用

struct node * dQueue(node *num)

反而。

这是对的。您应该查看它的定义位置或它应该做什么。

'linked_list2' : undeclared identifier
error C3861: 'createQueue': identifier not found
error C3861: 'addFront': identifier not found
error C3861: 'dQueue': identifier not found
error C3861: 'destroyList': identifier not found
error C3861: 'printList': identifier not found

这些都是由于缺乏定义造成的。修复第一个,这些错误也将消失。

于 2012-10-05T14:05:25.517 回答