I'm trying to write a simple linked list program. The header files are compiling successfully, but when I try to compile my driver program to test the program, I'm getting an error. Here's my driver program:
#include <iostream>
#include "Node.h"
#include "List.h"
using namespace std;
template <typename T>
void fill(List <T> &listObject)
{
T value;
cout << "Enter value (or 0 to end): ";
cin >> value;
while (value != 0)
{
listObject.insertAtBack(value);
cout << "Enter value (or 0 to end): ";
cin >> value;
}
}
int main()
{
List <int> integerList;
fill(integerList);
}
The error is flagged in my list.h file, (line 21). Here's the error:
error C2664: 'Node<NODETYPE>::Node(void *)' : cannot convert parameter 1 from 'const int' to 'void *'
template <typename NODETYPE>
void List <NODETYPE>::insertAtBack(const NODETYPE &value)
{
Node <NODETYPE> *newPtr = getNewNode(value);
if (isEmpty())
{
firstPtr = lastPtr = newPtr;
}
else
{
lastPtr->next = newPtr;
lastPtr = newPtr;
}
}
template <typename NODETYPE>
Node <NODETYPE> *List <NODETYPE>::getNewNode(const NODETYPE &value)
{
return new Node <NODETYPE> (value);
}
And, if it's a help, here's my Node.h file too:
#ifndef NODE_H
#define NODE_H
template <typename NODETYPE> class List;
template <typename NODETYPE>
class Node
{
friend class List<NODETYPE>;
void *info;
Node *next;
public:
Node(void *v) { info = v; next = 0;}
void put_next(Node *n) { next = n;}
Node *get_next() { return next; }
void *get_info() { return info; }
};
#endif
I think I'm doing something wrong with the templates, but am unsure. Thanks in advance for the help!