New objects in Binary Search Tree

I am working on a project, for school, that takes in a text file, creates objects of type Cat. Here is the loop to create cats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
while (inFile.good())
    {
        inFile >> name;
        inFile >> month;
        inFile.ignore (1, ',');
        inFile >> day;
        inFile.ignore (1, ',');
        inFile >> year;
        Date dOB (month, day, year);
        inFile >> weight;
        if(!inFile.good())
            break;
        Cat cat(name, dOB, weight);
        cat.display(cat);
        cout << endl;
        catBST.insert(cat);
    }


Everything goes screwy when I uncommonent catBST.insert(cat);
Here is the code for insert(const T & el)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
template<class T>
void BST<T>::insert(const T& el) 
{   
    BSTNode<T> *p = root, *prev = 0;

    // find a place for inserting new node;
    while (p != 0) 
    {        
        prev = p;
        if (p->key < el)
        {
            p = p->right;
        }
        else 
        {
            p = p->left;
        }
    }

    if (root == 0)    // tree is empty;
    {
        root = new BSTNode<T>(el);
    }
    else if (prev->key < el)
    {
        prev->right = new BSTNode<T>(el);
    }
    else 
    {
        prev->left  = new BSTNode<T>(el);
    }
}


Any help would be very much appreciated.
I have created BST's with simple data types and it works fine, but when I try with Cats or Dates (test case with Dates) I get compile errors.
I get the error C2784 mostly.
Last edited on
Hello CoffinNail,

you cannot place a function of a template class outside of that class
Topic archived. No new replies allowed.