#include <iostream>
usingnamespace 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) returnthis;
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