My code is as follows:
template <class Elem>
void LList<Elem>::LList(const int sz) { // ERROR
head = tail = curr = new link; // Create header
head->next = head;
}
template <class Elem>
void LList<Elem>::clear() { // Remove Elems
while (head->next != NULL) { // Return to free
curr = head->next; // (keep header)
head->next = curr->next;
delete curr;
}
tail = curr = head->next = head; // Reinitialize
}
// Insert Elem at current position
template <class Elem>
void LList<Elem>::insert(const Elem& item) {
assert(curr != NULL); // Must be pointing to Elem
curr->next = new link(item, curr->next);
if (tail->next != head) tail = tail->next;
}
template <class Elem> // Put at tail
void LList<Elem>::append(const Elem& item)
{ tail = tail->next = new link(item, head); }
// Move curr to next position
template <class Elem>
void LList<Elem>::next()
{ curr = curr->next; }
// Move curr to prev position
template <class Elem>
void LList<Elem>::prev() {
link* temp = curr;
while (temp->next!=curr) temp=temp->next;
curr = temp;
}
I use vscode to run this code, but it gives a compiler error for this part:
template<class Elem>
void LList<Elem>::LList(const int sz){ // ERROR
head = tail = curr = new link; // Create header
head->next = head;
}
The compiler error is:
LList is not a template
How can I fix the error?