Script started on Thu Mar 22 02:25:58 2001 [tsaiwn@ccbsd3] ListSTK> [tsaiwn@ccbsd3] ListSTK> cat -n mystk7.h 1 #include 2 using namespace std; 3 template 4 class MyStack { 5 list x; 6 public: 7 void push(const T& y) { 8 x.push_front(y); 9 } 10 T top( ) { 11 return x.front( ); 12 } 13 void pop( ) { 14 x.pop_front( ); 15 } 16 bool empty( ) { return x.begin() == x.end(); } 17 }; [tsaiwn@ccbsd3] ListSTK> cat -n mymain7.cpp 1 // mymain7.cpp; g++ mymain7.cpp ; ./a.out 2 using namespace std; 3 #include "mystk7.h" 4 //注意以下是 1999之後的 C++ 新寫法, 舊法使用 5 #include 6 int main( ){ 7 MyStack x; // 注意這! 8 x.push(880); 9 x.push(770); 10 x.push(53); 11 while(!x.empty()){ 12 cout << x.top(); x.pop(); 13 } 14 cout << endl; 15 } [tsaiwn@ccbsd3] ListSTK> g++ mymain7.cpp [tsaiwn@ccbsd3] ListSTK> ./a.out 53770880 [tsaiwn@ccbsd3] ListSTK> exit exit Script done on Thu Mar 22 02:28:58 2001