fork download
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. class Container {
  5. public:
  6. std::ostringstream bufferStream;
  7.  
  8. public:
  9. Container(); // constructor
  10. Container(const Container&); //Compy constructor
  11. ~Container();
  12. };
  13.  
  14. Container::Container() {
  15. bufferStream << "Hello ";
  16. }
  17.  
  18. Container::Container(const Container &c) {
  19. bufferStream << c.bufferStream.rdbuf();
  20. }
  21.  
  22. Container::~Container() {
  23. std::cout << bufferStream.str() << " [end]" << std::endl;
  24. }
  25.  
  26. // === Main method ===
  27.  
  28. int main() {
  29.  
  30. Container().bufferStream << "world"; // works fine
  31.  
  32. { // causes tons of compiler errors
  33. Container cont = Container();
  34. cont.bufferStream << "world!";
  35. }
  36.  
  37.  
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Hello world [end]
Hello world! [end]