由于头文件导致很多错误

时间:2012-10-05 13:54:27

标签: c

我在代码中遇到这些错误。我确信这些只是因为一些错误,但我无法找到它。请帮帮我!

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&gt;&gt; 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&gt;&gt; linklist.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 个答案:

答案 0 :(得分:5)

在C中,声明struct foo不会引入名为foo的类型。

你需要:

  • struct node
  • 的任何地方说node
  • 或添加typedef struct node node

答案 1 :(得分:1)

使用typedef结构而不仅仅是struct:

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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

error C2065: 'node' : undeclared identifier

正如它所说:标识符未声明。与C ++不同,C具有struct和其他内容的单独名称空间,因此请使用

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

这些都源于缺乏定义。修复第一个,这些错误也将消失。