Hi. I am working with the following code from a Data Structures text. When I try to instantiate a Stack object (as in Stack<int> s;), I get an error message in Dev-C++, "Instantiated from here," among others. Can anyone see what the problem might be? Thanks, Steve
Code:
#include<iostream>
using namespace std;
template<class T>
struct Node
{
T data;
Node<T> *next;
};
template<class T>
class Stack
{
private:
int count;
Node <T> top;
public:
Stack();
~Stack();
bool pushStack(T dataIn);
bool popStack(T& dataOut);
bool stackTop(T& dataOut);
bool emptyStack();
bool fullStack();
int stackCount();
};
template<class T>
Stack<T>::Stack()
:top(0), count(0){}
template<class T>
bool Stack<T>::pushStack(T dataIn)
{
bool success;
Node<T> *newPtr;
if(!(newPtr = new Node<T>))
success=false;
else
{
newPtr->data=dataIn;
newPtr->next=top;
top=newPtr;
count++;
success=true;
}
return success;
}
template<class T>
bool Stack<T>::popStack(T& dataOut)
{
Node<T> *dltPtr;
bool success;
if(count==0)
success=false;
else
{
dltPtr=top;
dataOut=top->data;
top=top->next;
count--;
success=true;
}
return success;
}
int main()
{
return 0;
}