"template declaration of 'TD<T> tree' "

1
2
3
4
5
6
7
8
template <typename T>
struct TD
{
	typedef TREE<T>* type;
};

template <typename T>
TD<T> tree;


I get the error at "TD<T> tree;" and I'm still really new to template programming in C++ so I don't have any idea of anything I can do to fix it -sorry I keep asking very similar questions - anybody?

I'm also getting an error that cout isn't defined in the scope of one of my methods even though I'm using the std namespace in my program (this is all in one header file), all the other questions I've seen only tell the asker that he should include the namespace so I'm kind of lost here too

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
template<typename T>
	void BSTClass<T>::Traversal(T d, ND<T> node)
	{
		if(node==NULL)
		{
			throw 1;
		}
		else
		{
			if(d < node->data)
			{
				Traversal(d,node->left);
			}
			else if (d > node->data)
			{
				Traversal(d,node->right);
			}
			else cout<<node->data + " " + node->colour + " " + node->left + " " + node->right;
		}
	}


again, help would really be appreciated - thanks guys
Just a note, you should not use namespaces in headers.

What are you trying to do on line 8? If you're trying to instantiate the template you made in the lines before, then you should remove line 7 and replace T in line 8 with a type, like so:
std::vector<int> an_integer_vector;

As for the cout problem, are you remembering to #include <iostream>? Just to make sure.

-Albatross
Last edited on
Actually I don't want to instantiate the template in line 8
I want to keep the type generic while creating a variable of that type.

Come to think of it though the variable I'm trying to create isn't really necessary since I pass the variables I use in my methods as parameters anyway so don't worry about it

Thanks about the <iostream> bit :) - missed that and I feel like a complete idiot because I keep missing the small things
Topic archived. No new replies allowed.