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

  1. //: C13:Newdel.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. // Simple demo of new & delete
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. class Tree {
  11.   int height;
  12. public:
  13.   Tree(int height) {
  14.     height = height;
  15.   }
  16.   ~Tree() { cout << "*"; }
  17.   friend ostream&
  18.   operator<<(ostream& os, const Tree* t) {
  19.     return os << "Tree height is: "
  20.               << t->height << endl;
  21.   }
  22. };
  23.  
  24. int main() {
  25.   Tree* t = new Tree(40);
  26.   cout << t;
  27.   delete t;
  28. } ///:~
  29.