Urgent help required

This is a discussion on Urgent help required within the C++ Programming forums, part of the General Programming Boards category; I have included below the class declarations and the struct I am using in my program. I am getting the ...

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

    Unhappy Urgent help required

    I have included below the class declarations and the struct I am using in my program.

    I am getting the following 3 error msg's:

    Cannot convert 'int' to 'Word' in functions BSTree<Word>::isEmpty() const
    Cannot convert 'char*' to 'Word' in function List::readList()
    Type mismatch in parameter 'data' in call to 'BSTree<Word>::insertData(const Word&)' in function List::readList()

    Can someone pls help me with this because I am totally lost


    Code:
    template <class T>
    class BTNode
    {
       friend class BSTree<T>;
    
       private:
    	BTNode (){left=right=NULL;}
    	BTNode (const T& el){info = el; left=right=NULL;}
    	T info;
    	BTNode<T> *left;
    	BTNode<T> *right;
    };
    Code:
    template <class T>
    class BSTree
    {
        friend class List;
    
        public:
    	BSTree (){root=NULL;};
    	BSTree (const BSTree<T>& rhs); 
    	BSTree<T>& operator= (const BSTree<T>& rhs);
    	~BSTree (){clear(root);}
    
    	T isEmpty () const {return root==NULL;}
    	void insertData (const T& data);
    
           private:
    	BTNode<T> *root;
    	void clear (BTNode<T> *treeRoot);
    	BTNode<T> *copyTree (BTNode<T> *treeRoot);
    	void insertHelper (BTNode<T> *&treeRoot, const T& 
    data);
    	void printInOrder (BTNode<T> *treeRoot);
    	int countNodes (BTNode<T> *treeRoot);
    };
    Code:
    const int MAX=20;
    
    struct Word
    {
        char wrd[MAX];
    
    };
    Code:
    class List
    {
      public:
             void readList ();
    
      private:
             Word x;  //struct obj
    };
    
    //==============================
    void Dict::readList ()
    {
        BSTree<Word> tmp;  //BSTree has type struct
    
        ifstream infile;
        infile.open ("wrdlist.txt");
    
        infile >> x.wrd;
    
        tmp.insertData (x.wrd);
        infile.close();
    }
    simple is always an understatement.....

  2. #2
    Unregistered
    Guest
    I answered a tree question the other day, but haven't really got time for yours at the moment. Just go through checking all your references and pointers, thi si a likely cause of "cannot convert" type errors

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    94
    I cant find the problem....pls pls someone help me
    simple is always an understatement.....

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > T isEmpty () const {return root==NULL;}

    root==NULL is a conditional expression, but your return type is T (Word). Maybe make the return type bool:
    bool isEmpty () const {return root==NULL;}

    > tmp.insertData (x.wrd);
    Should be:
    tmp.insertData (wrd);

    Since wrd.x is of type char *, not of type Word.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help required urgent!!
    By ikj in forum C++ Programming
    Replies: 2
    Last Post: 05-28-2009, 11:15 AM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. Urgent Help required.. pls help ??
    By intruder in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2003, 01:05 PM
  4. urgent help required
    By Nadia in forum C Programming
    Replies: 4
    Last Post: 12-10-2002, 06:10 AM
  5. Embedded SQL - urgent help required!
    By Robg in forum C Programming
    Replies: 1
    Last Post: 10-13-2001, 01:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21