Not sure what I'm doing wrong, but the only error I seem to be getting is:
visual studio 2010\projects\linked list\linked list\d_node.cpp(11): error C3861: 'outputList': identifier not found
Code:
#ifndef NODE_CLASS
#define NODE_CLASS
using namespace std;
// linked list node
template <typename T>
class node
{
public:
T nodeValue;
node<T> *next;
void addAtFront(node<T> *front, int val);
void outputList(node<T> *front);
// default constructor with no initial value
node() : next(NULL)
{}
// constructor. initialize nodeValue and next
node(const T& item, node<T> *nextNode = NULL) :
nodeValue(item), next(nextNode)
{}
};
template <typename T>
void node<T>::addAtFront(node<T> *front, int val)
{
node *newNode;
if(front == NULL)
{
newNode = new node<T>(val);
front = newNode;
}
else
{
newNode = new node<T>(val, front);
front = newNode;
}
}
template <typename T>
void node<T>::outputList(node<T> *front)
{
node<T> *ptr;
ptr = front;
while(ptr != NULL)
{
cout << ptr->nodeValue << " ";
ptr->next = ptr->next;
}
}
#endif // NODE_CLASS
Main:
Code:
#include <iostream>
#include "d_node.h"
using namespace std;
int main()
{
node<int> *head, obj1, obj2;
head = new node<int>;
obj1.addAtFront(head, 10);
obj2.addAtFront(head, 11);
outputList(head);
return 0;
}