I do not under stand how to get NODE to work. Worked fine with typedef struct but when I changed to template stopped working???

template<typename T>
struct Node 
{
	struct Node(T data)
	{
		this->data = data;
		previous = NULL;
		next = NULL;
	}
	T data;
	struct Node *previous;
	struct Node *next;
} NODE; 


 

template<typename T>
class LinkedList
{
protected:
	NODE *head;
	NODE *tail;

Recommended Answers

All 4 Replies

remove the 'struct' word in line 4

Tried removing struct from line 4. Still get the same error. The problem is with NODE on line 13. I get the error "C2143: syntax error : missing ';' before 'identifier'" however when I did it the first time with typedef struct no problems. is there a different way that I should be declaring NODE

template< typename T > struct Node 
{
	/*struct*/ Node( T data )
	{
		this->data = data;
		previous = NULL;
		next = NULL;
	}
	T data;
	/*struct*/ Node *previous; // keyword struct is superfluous here
	/*struct*/ Node *next;
} /*NODE*/ ; 

template< typename T > class LinkedList
{
    protected:
	/*NODE*/ Node<T>* head;
	/*NODE*/ Node<T>* tail;
};

vijayan121,

Perfect!! works good now thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.