Reputation: 2016
This is a linked list and I'm trying to implement a function (Push) that adds items onto the top of the list. For some reason Node < ItemType > *nnode = new node< ItemType >; inside the function is giving me an error: expected type-specifier before 'node'. This is how my professor taught me to implement stacks, linked lists, etc.
Am I implementing this wrong? I looked at other sites and they have almost identical code for linked lists.
#ifndef Linked_List_h
#define Linked_List_h
template <typename ItemType>
class Node
{
public:
ItemType Data;
Node <ItemType> *next;
};
template <typename ItemType>
class Linked_List
{
public:
Node <ItemType> *start;
Linked_List();
int Push(ItemType newitem);
}
#endif
.
#include "Linked_List.h"
template <typename ItemType>
Linked_List <ItemType>::Linked_List(){
start = NULL;
}
template <typename ItemType>
int Linked_List < ItemType >::Push(const ItemType newitem){
Node < ItemType > *nnode = new node< ItemType >; //not working
nnode -> Data = newitem;
nnode -> next = start;
start = nnode;
return 1;
}
Upvotes: 1
Views: 3608
Reputation: 20403
Does this help?
Node < ItemType > *nnode = new Node< ItemType >;
^
typo correction
Upvotes: 4