头文件 mystack.h
/**
* File mystack.h
* Declare class Stack
**/
#ifndef MYSTACK_H
#define MYSTACK_H
#include <iostream>
using namespace std;
enum Error_code { success, fail, underflow, overflow };
typedef char Stack_entry;
const int maxstack = 10;
class Stack
{
public:
Stack();
bool empty() const;
Error_code pop();
/**
* the top of the Stack is returned in item
**/
Error_code top(Stack_entry& item) const;
Error_code push(const Stack_entry& item);
private:
int count;
Stack_entry entry[maxstack];
};
#endif
预编译: g++ mystack.h
库文件 mystack.cpp
/**
* File mystack.cpp
**/
#include "mystack.h"
#include <iostream