Ощибка при компиляции! Undefined symbol: ArrayStack::ArrayStack()
ArrayStack.cpp
#include <cassert> // For assert// Header file
#include "ArrayStack.h"
template<class ItemType>
ArrayStack<ItemType>::ArrayStack() : top(-1){ }
template<class ItemType>
bool ArrayStack<ItemType>::isEmpty() const
{
return top < 0;
} // end isEmpty
template<class ItemType>
bool ArrayStack<ItemType>::push(const ItemType& newEntry)
{
bool result = false;
if (top < DEFAULT_CAPACITY - 1) // Does stack have room for newEntry?
{
top++;
items[top] = newEntry;
result = true;
} // end if
return result;
} // end push
template<class ItemType>
bool ArrayStack<ItemType>::pop()
{
bool result = false;
if (!isEmpty())
{
top--;
result = true;
} // end if
return result;
} // end pop
template<class ItemType>
ItemType ArrayStack<ItemType>::peek() const
{
assert(!isEmpty()); // Enforce precondition during debugging
// Stack is not empty; return top
return items[top];
} // end peek
// End of implementation file.
ArrayStack.h
#ifndef ARRAY_STACK_
#define ARRAY_STACK_
#include "StackInterface.h"
const int MAX_STACK = 20;
template<class ItemType>
class ArrayStack : public StackInterface<ItemType>
{
private:
static const int DEFAULT_CAPACITY = 50;
ItemType items[MAX_STACK];
int top;
public:
ArrayStack();
bool isEmpty() const;
bool push(const ItemType& newEntry);
bool pop();
ItemType peek() const;
};
// end ArrayStack
#endif
StackInterface.h
#ifndef STACKINTERFACE_H_
#define STACKINTERFACE_H_
template <class ItemType>
class StackInterface
{
public:
virtual bool isEmpty() const = 0;
virtual bool push(const ItemType& newEntry) = 0;
virtual bool pop() = 0;
virtual ItemType peek() const = 0;
virtual ~StackInterface() { }
};
# endif