我試圖在我的項目中使用鏈表來實現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
我不會在頭文件中放置「using namespace」指令,尤其是不是標準文件(不是你似乎正在使用任何東西)。另外爲什麼LinkedList.h需要#include PieceTable.h?他們都試圖包容對方! –
我做到了這一點(包括piecetable和包括鏈表)作爲一個絕望的嘗試來解決這個問題:P – devjeetroy