Pointers to a template class

I want to make a list and print it using the class below.

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
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
using namespace std;

template <class T> class Link {
public:
	Link(const T& v, Link<T>* p = 0, Link<T>* s = 0): value(v), prev(p), succ(s) { }
	
 Link<T>* insert(Link<T>*);  // OK
 Link<T>* next() const { return succ; }  // OK
 Link<T>* previous() const {return prev; }  // OK
 T get_value() { return value; }
    
private:
	T value;
	Link* prev;
	Link* succ;
};

//-----------------------------------------------------

template <class T> Link<T>* Link::insert(Link<T>* n)  //insert n before "this", return n
{
	if(n == 0) return this;
	if(this == 0) return n;
	n->succ = this;
	if(prev) prev -> succ = n;
	n -> prev = prev;
	prev = n;
	return n;
}

//------------------------------------------------

template <class T> void link_print_all(Link<T>* p)
{
    cout <<"{ ";
	while(p) {
		cout << p -> get_value();
		if(p = p -> next()) cout << ", ";
	}
	cout << " }\n";
}
 
//--------------------------------

int main() 
{
	Link<string>* norse_gods = new Link<string> ("Thor");
	norse_gods = norse_gods -> insert(new Link<string>("Odin"));

	cout << "norse_gods are: "; link_print_all<string>(norse_gods);
	cout << "\n";
	return 0;
}


After running, I get two errors. I tried to find the problem but couldn't unfortunately. Could you please help me?

The errors are as follows:

Error 1 error C2955: 'Link' : use of class template requires template argument list
Error 2 error C2244: 'Link<T>::insert' : unable to match function definition to an existing declaration




Last edited on
You forgot to write Link<T> when defining the insert function.
Thank you very much for your precise answer.
Topic archived. No new replies allowed.