|38| error: invalid use of template-name 'tnode' without an argument list|

Why can't I create a new tnode in the bstree (Binary Search Tree) class?

TNode.h------------------------------
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
 #include <iostream>
#include <cstddef>
#include <vector>
#ifndef TNode_h
#define TNode_h
using namespace std;
template <class T>
class tnode{
public:
    tnode *left;
    tnode *right;
    T key;

    tnode(T data)
    {
    key = data;
    left = NULL;
    right = NULL;
    }





};
#endif


bst.h---------------------------
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
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <cstddef>
#include "TNode.h"

using namespace std;
template <class T>
class bstree
{

public:



    bstree()
    {
        root = NULL;
    }

    void insert(T &k)
    {
        if (root == NULL)
        root = new tnode(k);


    }











private:
        tnode *root; //error right here




};
Last edited on
tnode<T> *root
Thank you very much. :)
Also in my main, I get |9|error: missing template arguments before 'obj'|

main.cpp--------------
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <vector>
#include "bst.h"

using namespace std;

int main()
{
bstree obj;
obj.insert(5);
    cin.get();
    return 0;
}

1
2
3
bstree obj;//What do you store in your obj? Integers? Doubles? Bananas?
//use 
bstree<int> obj;
Haha bananas. Well, let's say I am to make a BST, which takes in letters, numbers, and operators such as " + - * / ". How would I go abou that. Would I have to make a new object everytime in order to add a different value everytime?
So you want ot store different data types in one container? And how will you differentiate between them?
Yea, for example
obj.insert(5);
obj.insert('d');
obj.insert('*');
obj.insert('+');

and I will use the BST class to give them priorities!
And how would you do that? I am not saying it is impossible, but it is above-average level at the best.
That's what I'm trying to figure out because I am new to templates.
Also in the bst class whenever I insert the "* - + /" it will have higher priority making it the root node and making the older nodes it's children based on value!
Last edited on
I still can't figure it out.
Topic archived. No new replies allowed.