home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C14 / InheritStack.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  888 b   |  39 lines

  1. //: C14:InheritStack.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. //{L} ../C13/Stack4
  7. // Specializing the Stack class
  8. #include "../C13/Stack4.h"
  9. #include "../require.h"
  10. #include <iostream>
  11. #include <fstream>
  12. #include <string>
  13. using namespace std;
  14.  
  15. class StringList : public Stack {
  16. public:
  17.   void push(string* str) {
  18.     Stack::push(str);
  19.   }
  20.   string* peek() const {
  21.     return (string*)Stack::peek();
  22.   }
  23.   string* pop() {
  24.     return (string*)Stack::pop();
  25.   }
  26. };
  27.  
  28. int main() {
  29.   ifstream file("InheritStack.cpp");
  30.   assure(file, "InheritStack.cpp");
  31.   string line;
  32.   StringList textlines;
  33.   while(getline(file,line))
  34.     textlines.push(new string(line));
  35.   string* s;
  36.   while((s = textlines.pop()) != 0) // No cast!
  37.     cout << *s << endl;
  38. } ///:~
  39.