list.h file:
#ifndef __FwrdLinkList__list__
#define __FwrdLinkList__list__
#include <iostream>
// To be developed once the lecture is completed
//#include "node_iterator.h"
// Class definition
template <typename T>
class list
{
public:
//typedef node_iterator<T> iterator;
// Constructors **********************************************************
//Pre: Default constructor
//Post: Constructor just sets the head pointer to NULL
list():head(0), used(0){}
//Pre:
//Post:
list(const list<T>& copy);
~list();
//Pre:
//Post:
void pushFront(const T&);
private:
// node struct needs to be at top for template!
struct node
{
T data;
node* link;
node(const T& val=T(), node* n=0):data(val),link(n) {}
};
node* head;
unsigned used;
node* copy(node*);
};
#include "list_tem.h"
#endif /* defined(__FwrdLinkList__list__) */
list_tem.h file
template <typename T>
list<T>::list(const list& copy) //HERE IS BOTH ERRORS ( Expected unqualified-id, unknown type name 'list' )
{
typename list<T>::node* temp = new typename list<T>::node(*copy.head);
this->head = temp;
this->used = copy.used;
}
template <typename T>
list<T>::~list()
{
node *tmp;
while (head)
{
tmp = head;
head = head->link;
delete tmp;
}
}
template <typename T>
void list<T>::pushFront(const T& val)
{
node *newNode = new node(val,0);
used++;
if (used == 0)
{
head = newNode;
return;
}
newNode->link = head;
head = newNode;
return;
}

New Topic/Question
Reply



MultiQuote





|