What could be wrong about this template?
Code:
StackA.h
#ifndef STACKA_H
#define STACKA_H
// *********************************************************
// Header file StackA.h for the ADT stack.
// Array-based implementation.
// *********************************************************
#include "StackException.h"
#include
const int MAX_STACK = 100;
template < class StackItemType >
class Stack
{
public:
// constructors and destructor:
Stack(); // default constructor
// stack operations:
bool isEmpty() const;
void push(StackItemType newItem) throw(StackException);
void pop() throw(StackException);
void pop(StackItemType& stackTop) throw(StackException);
void getTop(StackItemType& stackTop) const
throw(StackException);
private:
StackItemType items[MAX_STACK]; // array of stack items
int top; // index to top of stack
}; // end class
#endif
StackA.cpp
// *********************************************************
// Implementation file StackA.cpp for the ADT stack.
// Array-based implementation.
// *********************************************************
#include "StackA.h" // Stack class specification file
#include "StackException.h"
template < class StackItemType >
Stack::Stack(): top(-1)
{
} // end default constructor
template < class StackItemType >
bool Stack::isEmpty() const
{
return top < 0;
} // end isEmpty
template < class StackItemType >
void Stack::push(StackItemType newItem) throw(StackException)
{
// if stack has no more room for another item
if (top >= MAX_STACK-1)
throw StackException("StackException: stack full on push");
else
{ ++top;
items[top] = newItem;
} // end if
} // end push
template < class StackItemType >
void Stack::pop() throw(StackException)
{
if (isEmpty())
throw StackException("StackException: stack empty on pop");
else
--top; // stack is not empty; pop top
} // end pop
template < class StackItemType >
void Stack::pop(StackItemType& stackTop) throw(StackException)
{
if (isEmpty())
throw StackException("StackException: stack empty on pop");
else
{ // stack is not empty; retrieve top
stackTop = items[top];
--top; // pop top
} // end if
} // end pop
template < class StackItemType >
void Stack::getTop(StackItemType& stackTop) const throw(StackException)
{
if (isEmpty())
throw StackException("StackException: stack empty on getTop");
else
// stack is not empty; retrieve top
stackTop = items[top];
} // end getTop
// End of implementation file.
in main function of a driver class,
Code:
Stack< char > myStack;
The Visual Studio 2005 compiler gives me 6 errors that I cannot understand anything from them.
Here some of them;
Error 22 error LNK2019: unresolved external symbol "public: bool __thiscall Stack::isEmpty(void)const " (?isEmpty@?$Stack@D@@QBE_NXZ) referenced in function "class std::basic_string,class std::allocator > __cdecl convertInfixToPostfix(class std::basic_string,class std::allocator >)" (?convertInfixToPostfix@@YA?AV?$basic_string@DU?$c har_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) InfixCalculator
Error 23 error LNK2019: unresolved external symbol "public: void __thiscall Stack::pop(void)" (?pop@?$Stack@D@@QAEXXZ) referenced in function "class std::basic_string,class std::allocator > __cdecl convertInfixToPostfix(class std::basic_string,class std::allocator >)" (?convertInfixToPostfix@@YA?AV?$basic_string@DU?$c har_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) InfixCalculator
Error 27 fatal error LNK1120: 5 unresolved externals InfixCalculator
Any help would be appriciated,
Thanks in advance.