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

  1. //: C08:ConstInitialization.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. // Initializing const in classes
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. class Fred {
  11.   const int size;
  12. public:
  13.   Fred(int sz);
  14.   void print();
  15. };
  16.  
  17. Fred::Fred(int sz) : size(sz) {}
  18. void Fred::print() { cout << size << endl; }
  19.  
  20. int main() {
  21.   Fred a(1), b(2), c(3);
  22.   a.print(), b.print(), c.print();
  23. } ///:~
  24.