// This stuff belongs in Stack.h
// so doxygen comments are needed in here.
// Stack class
// Nicola Ritter
// modified smr
//——————————————-
#ifndef MY_STACK
#define MY_STACK
//——————————————-
#include
#include
using namespace std;
//——————————————-
template
class Stack
{
public:
Stack () {};
~Stack () {};
bool Push(const T &data);
bool Pop (T &data);
bool Empty () {return m_stack.empty();} // normally body is in the .cpp file but this is a template class, so put it below.
private:
stack
};
//——————————————-
// It is a template, so we have to put all the code
// in the header file
// If it wasn’t a template, it would go into Stack.cpp
//——————————————-
template
bool Stack
{
bool okay = true;
try
{
m_stack.push(data);
}
catch (…)
{
okay = false;
}
return okay;
}
//——————————————-
template
bool Stack
{
if (m_stack.size() > 0)
{
data = m_stack.top();
m_stack.pop();
return true;
}
else
{
return false;
}
}
//——————————————-
#endif