template <class> question

Wondering what the difference is in declaring attributes and methods in a class which uses template<>? For example, the code pasted below declares some with <Type> and some without. This compiles in VS2008, and the full code for the List runs as expected. Is there any difference to either form of syntax? If not, is one preferred?

1
2
3
4
5
6
7
8
9
10
template <class Type>
class ListNode
{
private:
	Type data;
	ListNode<Type>* next;
	ListNode* previous;
public:
	ListNode<Type>(const Type & newData, ListNode * nextPtr = NULL, ListNode * previousPtr = NULL): data(newData), next(nextPtr), previous(previousPtr) { }
	~ListNode() { cout << "Destroy ListNode: " << data << endl; }


Thanks,
Sammie
AFAIK, as long as you have the implementation within the class (and you should have) it makes no difference. It is a matter of style.

I prefer to leave it out. At the time you implement the method you ought to know that it is a method template - after all, you're implementing a class template...
I'm not 100% sure, but I think the examples on lines 6 and 9 where the <Type> is used are not standards compliant and will generate compile errors on newer compilers.
Topic archived. No new replies allowed.