【发布时间】:2011-11-20 22:39:39
【问题描述】:
我试图在我的一个项目中使用链接列表来实现一块表数据结构。我的项目有7个文件,如下:
LinkedList.cpp
LinkedList.h
Node.cpp
Node.h
PieceTable.h
PieceTable.cpp
- Main.cpp
所以这里的问题是,在我的类PieceTable 中,我有一个LinkedList 类型的数据成员。直到昨天一切都很好。我已经多次构建了该项目,并且运行良好。今天早上,我在LinkedList 中添加了一个功能,在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 是一个未定义的类
这里是头文件:
拼图:
#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
链表:
#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
【问题讨论】:
-
我不会在头文件中放置“使用命名空间”指令,尤其是 std(不是你似乎在使用它的任何东西)。另外为什么 LinkedList.h 需要#include PieceTable.h?他们都试图互相包容!
-
我这样做(包括piecetable和包括linkedlist)作为解决这个问题的绝望尝试:P