我试图在我的项目中使用链接列表实现一个Piece Table数据结构。我的项目有7个文件,如下:
LinkedList.cpp
LinkedList.h
Node.cpp
Node.h
PieceTable.h
PieceTable.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
答案 0 :(得分:2)
这是一个相当简单的循环包含:piecetable.h
包括linkedlist.h
,linkedlist.h
错误地包含piecetable.h
。我相信您可以删除第二个包含内容,并且可以从class LinkedList
中删除piecetable.h
的前向声明。