Iv always had trouble with templates and I always get the same error message "Error: Templates can only declare classes or functions."
program is a template linked list class and I'm using the sun studio 12 C++ compiler
linkedList.h file:
#include "nodeType.h"
using namespace std;
template <class Storeable>
class LinkedList
{
public:
LinkedList();
//default constructor
bool isEmpty();
//Postcondition: should return true if list is empty,
//false if the list is not empty
.
.
.
~LinkedList();
//destructor
private:
nodeType<Storeable> *first;
//pointer to the first node in the list
nodeType<Storeable> *last;
//pointer to the last node in the list
};
linkedList.cpp file:
#include "linkedList.h"
using namespace std;
template <class Storeable>
linkedList<Storeable>::linkedList()
{
first = NULL;
last = NULL;
}
template <class Storeable>
linkedList<Storeable>::isEmpty()
{
if(first == NULL)
return true;
else
return false;
}
.
.
.
I'm basically get that "Error: Templates can only declare classes or functions." every line where "template<class Storeable>" is in the linkedList.cpp file. I'v been searching google and couldn't find anything. any help is appreciated