0

コードでこれらのエラーが発生しています。これらは1つの間違いによるものだと確信していますが、見つけることができません。私を助けてください!

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

以下は 3 つのファイル ファイル 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 >> 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

4 に答える 4

5

Cでは、宣言は。struct fooと呼ばれる型を導入しませんfoo

必要がある:

  • あなたが言うstruct nodeところはどこでも言ってくださいnode
  • またはを追加しtypedef struct node nodeます。
于 2012-10-05T14:03:36.403 に答える
1

struct だけでなく typedef 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 に答える