fork(1) download
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. class Logger : public std::ostringstream
  5. {
  6. public:
  7. ~Logger()
  8. {
  9. std::cout << this->str() << std::endl;
  10. }
  11.  
  12. Logger& stream()
  13. {
  14. return *this;
  15. }
  16. };
  17.  
  18. int main( int argc, char ** argv )
  19. {
  20. // 1.
  21. // Prints an address, e.g. 0x106e89d5c.
  22. Logger() << "foo";
  23.  
  24. // 2.
  25. // Works as expected.
  26. Logger().stream() << "foo";
  27.  
  28. // What is the difference between 1. and 2.?
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
0x80498b4
foo