C++ Visual Studio关于多个类的荒谬错误

C++ Visual Studio关于多个类的荒谬错误,c++,visual-studio-2010,C++,Visual Studio 2010,在我的一个项目中,我试图使用链表实现一个工件表数据结构。我的项目有7个文件,如下所示: LinkedList.cpp LinkedList.h Node.cpp Node.h 可分段的 PieceTable.cpp Main.cpp 所以这里的问题是,在我的类PieceTable中,我有一个类型为LinkedList的数据成员。直到昨天一切都很好。我已经建立了该项目多次,它是良好的工作。今天早上,我在LinkedList中添加了一个函数,在PieceTable中添加了另一个函数。当我尝试to

在我的一个项目中,我试图使用链表实现一个工件表数据结构。我的项目有7个文件,如下所示:

  • LinkedList.cpp

  • LinkedList.h

  • Node.cpp

  • Node.h

  • 可分段的

  • PieceTable.cpp

  • Main.cpp
所以这里的问题是,在我的类
PieceTable
中,我有一个类型为
LinkedList
的数据成员。直到昨天一切都很好。我已经建立了该项目多次,它是良好的工作。今天早上,我在
LinkedList
中添加了一个函数,在
PieceTable中添加了另一个函数。当我尝试top build时,编译器说:

1>c:\users\devjeet\documents\visual studio 2010\projects\piece table\piece table\piecetable.h(33): error C2079: 'PieceTable::dList' uses undefined class 'LinkedList'
dList是LinkedList类型的类成员的名称。我甚至提出了一个类声明,编译器在声明中说了一些意思:

LinkedList是一个未定义的类

以下是头文件:

可分段:

#ifndef PIECETABLE_H
#define PIECETABLE_H
#include <Windows.h>
#include <iostream>
#include "LinkedList.h"
#include "Node.h"

class LinkedList;

using namespace std;

class PieceTable
{
public:
    PieceTable(void);
    ~PieceTable(void);

    //buffer realated functions
    void setBuffer(char buffer[]);

    //printing functions
    void printBuffer();
    void printTable();


    //text insertion functions 
    void insertTextAfterPosition(char text, const int& position);
private:
    LinkedList dList;
    char* originalBuffer;
    char* editBuffer;
    int bufferLength;
    int editBufferCounter;

};
#endif
请注意,无论是一次性使用
#pragma
还是
#ifndef/#endif

谢谢


Devjeet

这是一个相当直接的循环包含:
piecetable.h
包括
linkedlist.h
,而
linkedlist.h
错误地包括
piecetable.h
。我相信您可以删除第二个包含项,并且可以从
piecetable.h

中删除
class LinkedList
的前向声明。我不会在头文件中添加“using namespace”指令,尤其不是std(也不是说您似乎正在使用其中的任何内容)。还有,为什么LinkedList.h需要包含PieceTable.h?他们都在试图把对方包括进来!我这样做(包括piecetable和linkedlist)是为了解决这个问题:感谢您的回复。我只是这么做了,它没有改变
节点的任何内容检查。h
也有虚假的包含。
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include "Node.h"
#include "PieceTable.h"

class Node;

class LinkedList
{
public:
    LinkedList();
    ~LinkedList();

    bool isEmpty() const;

    //functions that deal with getting nodes
    Node* getNodeAtPosition(const int& position) const;
    Node* getFront() const;
    Node* getBack() const;
    Node* getHead()const;
    Node* getTail()const;
    Node* getNodeFromOffset(const int& offset) const;

    //functions that deal with adding nodes
    void append(const int offset, const int& length,const bool descriptor);
    void add(Node* node, const int offset, const int& length,const bool descroptor);                                //adds a node after the given node
    void insertNodeAfterPosition(const int offset, const int& length,const bool descriptor, const int& position);

    //function concerned with deletion
    void removeNode(Node* node);
    void deleteNodeAtPosition(const int& position);
    void removeBack();
    void removeFront();
    void emptyList();

    //debugging functions
    void printNodes();
private:
    Node* head;
    Node* tail;
};

#endif