Script started on Tue Mar 27 12:27:58 2001
[tsaiwn@ccbsd3] ListSTK> g++ mymain8.cpp
[tsaiwn@ccbsd3] ListSTK> ./a.out 
53770880
[tsaiwn@ccbsd3] ListSTK> cat -n mystk8.h
     1  #ifndef _MYSTK8_H_
     2  #define _MYSTK8_H_
     3  //mystk8.h  --- @CopyLeft by tsaiwn@csie.nctu.edu.tw
     4  // implement a stack using a <list> via Inheritance method
     5  // 注意這版本是用 Inheritance 的方式, 不是用 contains 的方式
     6  #include <list>
     7  using namespace std;
     8  template <class T>
     9  class MyStack: list<T> {
    10  public:
    11     void push(const T& y) {
    12        MyStack<T>::push_front(y);
    13     }
    14     T top( ) {
    15        return MyStack<T>::front( );
    16     }
    17     void pop( ) {
    18        MyStack<T>::pop_front( );
    19     }
    20     bool empty( ) 
    21      { return MyStack<T>::begin() == MyStack<T>::end(); }
    22  };
    23  #endif

[tsaiwn@ccbsd3] ListSTK> cat -n mymain8.cpp
     1  // mymain8.cpp -- CopyLeft by tsaiwn@csie.nctu.edu.tw
     2  // g++ mymain8.cpp  ; ./a.out
     3  using namespace std;
     4  #include "mystk8.h"
     5  //注意以下是 1999之後的 C++ 新寫法, 舊法使用 <iostream.h>
     6  #include <iostream>
     7  int main( ){
     8     MyStack <int> x;    // 注意這!
     9     x.push(880);
    10     x.push(770);
    11     x.push(53);
    12     while(!x.empty()){
    13        cout << x.top();  x.pop();
    14     }
    15     cout << endl;
    16  }

[tsaiwn@ccbsd3] ListSTK> g++ mymain8.cpp
[tsaiwn@ccbsd3] ListSTK> ./a.out 
53770880
[tsaiwn@ccbsd3] ListSTK> exit 
exit

Script done on Tue Mar 27 12:28:58 2001