I'm currently doing an assignment for course and it involves creating a template class. I have the template class set up and everything, but I'm getting errors that I can't seem to fix. I have tried various solutions and neither have worked so far, I have also done a reasonable amount of research and found no answers, precisely relevant to my scenario, concerning the problem although many others have asked.
Here is the code thus far...
#ifndef STACK_H
#define STACK_H
#include "Queue.h"
#include "MyException.h"
#include <iostream>
using namespace std;
template<class T>
class Stack;
template<class T>
ostream& operator<<(ostream&,Stack<T>&);
template<class T>
class Stack
{
public:
Stack();
Stack(const Stack<T>& other);
void push(const T& el);
T pop();
T peek();
bool isEmpty();
friend ostream& operator<< <T>(ostream&,Stack<T>&);
Stack<T>& operator=(const Stack<T>& other);~Stack();
private:
class Node
{
public:
Node(const T& data, Node* n = 0)
{
element = data;
next = n;
}
T element;
Node* next;
};
Node* top;
};
#include "Stack.cpp"
#endif
that is the "Stack.h" and then there is
template<class T>
Stack<T>::Stack()
{
}
template <class T>
Stack<T>::Stack(const Stack<T>& other)
{
}
template <class T>
void Stack<T>::push(const T& el)
{
}
template <class T>
T Stack<T>::pop()
{
}
template <class T>
T Stack<T>::peek()
{
}
template <class T>
bool Stack<T>::isEmpty()
{
return false;
}
that is the "Stack.cpp". I understand that the implementation being in a different file is not the generally accepted method, but unfortunately that is where the code needs to be. Now when I run this even without any real code, so to speak, i get the following errors.
3: expected constructor, destructor, or type conversion before '<' token
3: expected ';' before '<' token
9: expected constructor, destructor, or type conversion before '<' token
9: expected ';' before '<' token
17: expected init-declarator before '<' token
17: expected ';' before '<' token
23: expected init-declatator before '<' token
23: expected ';' before '<' token
and it goes on like that for each function up unto line 35.
Now, could it be my compiler? Could it be that I haven't finished all the functions and returned something yet?
Any help whatsoever would be largely appreciated, thanks.