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

Apr 23, 2013 at 6:15pm
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 Apr 23, 2013 at 6:15pm
Apr 23, 2013 at 6:18pm
tnode<T> *root
Apr 23, 2013 at 6:20pm
Thank you very much. :)
Apr 23, 2013 at 6:30pm
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;
}

Apr 23, 2013 at 6:42pm
1
2
3
bstree obj;//What do you store in your obj? Integers? Doubles? Bananas?
//use 
bstree<int> obj;
Apr 23, 2013 at 6:46pm
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?
Apr 23, 2013 at 6:59pm
So you want ot store different data types in one container? And how will you differentiate between them?
Apr 23, 2013 at 7:08pm
Yea, for example
obj.insert(5);
obj.insert('d');
obj.insert('*');
obj.insert('+');

and I will use the BST class to give them priorities!
Apr 23, 2013 at 7:18pm
And how would you do that? I am not saying it is impossible, but it is above-average level at the best.
Apr 23, 2013 at 7:24pm
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 Apr 23, 2013 at 7:29pm
Apr 23, 2013 at 8:33pm
I still can't figure it out.
Topic archived. No new replies allowed.