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

  1. //: C08:ConstTemporary.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. // Temporaries are const
  7.  
  8. class X {};
  9.  
  10. X f() { return X(); } // Return by value
  11.  
  12. void g1(X&) {} // Pass by non-const reference
  13. void g2(const X&) {} // Pass by const reference
  14.  
  15. int main() {
  16.   // Error: const temporary created by f():
  17. //!  g1(f());
  18.   // OK: g2 takes a const reference:
  19.   g2(f());
  20. } ///:~
  21.