-
template problem
I am getting the following error msg and cant understand why :confused:
> Compiling MAIN.CPP:
> Error AVLTREE.H 24: Undefined structure 'Dictionary'
> Error AVLTREE.H 24: Size of 'info' is unknown or zero
> Error AVLTREE.H 24: Undefined structure 'Dictionary'
The declarations and includes for each class is as follows:
ontology.h
Code:
#include "diction.h"
class Ontology: public Dictionary
{
private:
MyString strObj;
AVLtree<MyString> treeObj;
void createOntologyTree ();
public:
Ontology () {strObj.ID=0;};
~Ontology (){infile.close(); outfile.close();};
void readXMLfile ();
};
diction.h
Code:
#include "generator.h"
class Dictionary :public Generator
{
protected:
MyString str;
AVLtree<Dictionary> avlObj;
void createOntologyDict (MyString str);
public:
int ID;
char key[MAX];
Dictionary () {ID=0;};
};
generator.h
Code:
#include "avltree.h"
#include "mystring.h"
#include "diction.h"
class Dictionary; //forward declaration
class Ontology; //forward declaration
class Generator: public AVLtree<MyString>, public AVLtree<Dictionary>
{
protected:
//.....
public:
ifstream infile;
ofstream outfile;
};
mystring.h
Code:
struct MyString
{
friend ostream& operator << (ostream& os, const MyString& obj);
int operator == (const MyString& obj) const;
int operator < (const MyString& obj) const;
int operator > (const MyString& obj) const;
char metaData[MAX];
char category[MAX];
char subCategory[MAX];
char keyWrd[MAX];
long ID;
};
avltree.h
Code:
template <class T>
struct AVLnode
{
friend class AVLtree<T>;
T info; <-- error points to here
int balance;
AVLnode<T> *right;
AVLnode<T> *left;
AVLnode () {right = left = NULL;}
};
//============================================
template <class T>
class AVLtree
{
public:
int count;
AVLnode<T> *tree, *walker;
AVLtree () {tree=walker=NULL; count=0;};
~AVLtree () {clear(tree);};
int insertData (const T &data);
void printAVLtree () {printInOrder(tree);};
protected:
void clear (AVLnode<T> *tree);
void insertHelper (AVLnode<T>* &root, AVLnode<T>*node, bool &higher);
void rightBalance (AVLnode<T> *&root, bool &higher);
void leftBalance (AVLnode<T> *&root, bool &higher);
AVLnode<T>* rotateRight (AVLnode<T> *root);
AVLnode<T>* rotateLeft (AVLnode<T> *root);
void printInOrder (AVLnode<T> *root);
};
I cant see what it is that I am missing or have done wrong...
Also...
Code:
AVLtree<MyString> <-- was working fine
AVLtree<Dictionary> <-- errors started occuring when I created this
Am I allowed to use both of these at the same time?
Sophie
-
put a forward declaration in the avltree.h, or switching the order of your #includes in your generator.h might fix things
may I also ask why your dictionary class has an AVLTree of type Dictionary?
-
> may I also ask why your dictionary class has an AVLTree of type Dictionary?
Because the dictionary obj currently requires only the key[] and the id, which will be stored as a separate tree and will be further used within the generator class.
As you may or may not have realised...this project I am working on is a metadata generator. It is a project that I have been assigned to do by my uni for one of Australia's major broadcasting organisations.
....I have been playing around with the order and includes and have not got anywhere. Any other suggestions.
-