2011-11-20 42 views
0

我试图在我的项目中使用链表来实现Piece Table数据结构。我的项目有7个文件,如下所示:关于多个类的Visual Studio中的荒谬错误

  • LinkedList.cpp

  • LinkedList.h

  • Node.cpp

  • Node.h

  • PieceTable。 h

  • PieceTable.cpp

  • Main.cpp的

所以这里的问题是,在我的PieceTable课,我有LinkedList类型的数据成员。一切都很好,直到昨天。我多次创建了该项目,并且运行良好。今天早上,我给LinkedList增加了1个功能,另外一个增加了PieceTable。当我尝试构建它时,编译器会说:

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的是一个未定义类

这里是头文件:

PieceTable:

#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 

LinkedList:

#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 

注意,发生的问题我是否使用#pragma once#ifndef/#endif

谢谢,

Devjeet

+1

我不会在头文件中放置“using namespace”指令,尤其是不是标准文件(不是你似乎正在使用任何东西)。另外为什么LinkedList.h需要#include PieceTable.h?他们都试图包容对方! –

+0

我做到了这一点(包括piecetable和包括链表)作为一个绝望的尝试来解决这个问题:P – devjeetroy

回答

2

这是一个相当直接的圆形夹杂:piecetable.h包括linkedlist.h,和linkedlist.h错误地包括piecetable.h。我相信您可以删除第二个内容,并且您可以从piecetable.h中删除前向声明class LinkedList

+0

感谢您的回应。我只是这样做,它不会改变一件事 – devjeetroy

+0

检查'node.h'也有虚假的内含物。 –

+0

谢谢!它做了!它正在工作!非常感谢! – devjeetroy