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

  1. //: C14:Compose.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. // Reuse code with composition
  7. #include "Useful.h"
  8.  
  9. class Y {
  10.   int i;
  11. public:
  12.   X x; // Embedded object
  13.   Y() { i = 0; }
  14.   void f(int ii) { i = ii; }
  15.   int g() const { return i; }
  16. };
  17.  
  18. int main() {
  19.   Y y;
  20.   y.f(47);
  21.   y.x.set(37); // Access the embedded object
  22. } ///:~
  23.