home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C10 / Statinit.cpp < prev   
Encoding:
C/C++ Source or Header  |  2000-05-25  |  585 b   |  30 lines

  1. //: C10:Statinit.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. // Scope of static initializer
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. int x = 100;
  11.  
  12. class WithStatic {
  13.   static int x;
  14.   static int y;
  15. public:
  16.   void print() const {
  17.     cout << "WithStatic::x = " << x << endl;
  18.     cout << "WithStatic::y = " << y << endl;
  19.   }
  20. };
  21.  
  22. int WithStatic::x = 1;
  23. int WithStatic::y = x + 1;
  24. // WithStatic::x NOT ::x
  25.  
  26. int main() {
  27.   WithStatic ws;
  28.   ws.print();
  29. } ///:~
  30.