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 //mystk8.h --- CopyLeft by tsaiwn@csie.nctu.edu.tw 2 // implement a stack using a via Inheritance method 3 // 注意這版本是用 Inheritance 的方式, 不是用 contains 的方式 4 #include 5 using namespace std; 6 template 7 class MyStack: list { // 注意這寫法 -- Inheritance 8 public: 9 void push(const T& y) { 10 MyStack::push_front(y); 11 } 12 T top( ) { 13 return MyStack::front( ); 14 } 15 void pop( ) { 16 MyStack::pop_front( ); 17 } 18 bool empty( ) 19 { return MyStack::begin() == MyStack::end(); } 20 }; [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++ 新寫法, 舊法使用 6 #include 7 int main( ){ 8 MyStack 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