Thread: template problem

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    94

    Unhappy template problem

    I am getting the following error msg and cant understand why

    > 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
    Last edited by sweets; 04-18-2004 at 12:27 PM.
    simple is always an understatement.....

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    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?
    Last edited by skorman00; 04-18-2004 at 11:36 AM.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    94
    > 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.
    simple is always an understatement.....

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Read this post.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template object creation problem
    By babu198649 in forum C++ Programming
    Replies: 7
    Last Post: 09-16-2008, 04:02 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  5. Problem with template usage
    By rmullen3 in forum C++ Programming
    Replies: 2
    Last Post: 02-23-2002, 06:30 PM