I was trying to implement a Piece Table data structure using Linked Lists in a project of mine. My project has 7 files, as follows:
-
LinkedList.cpp
-
LinkedList.h
-
Node.cpp
-
Node.h
-
PieceTable.h
-
PieceTable.cpp
- Main.cpp
So the problem here is that in my class PieceTable, I have a data member of type LinkedList. Everything was fine till yesterday. I had built the project multiple times and it was working good. Today, in the morning, I added 1 function to LinkedList and another to PieceTable. When I tried top build it, the compiler says:
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 is the name of the class member of type LinkedList. I even put a forward class declaration, upon which the compiler said something that meant :
LinkedList is an undefined class
Here are the header files :
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
Note that the problem occurs whether I use #pragma once or #ifndef/#endif
Thanks,
Devjeet
This is a fairly straight-forward circular inclusion:
piecetable.hincludeslinkedlist.h, andlinkedlist.herroneously includespiecetable.h. I believe you can remove the second inclusion, and you can remove the forward declaration ofclass LinkedListfrompiecetable.h.