fork(2) download
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std;
  4.  
  5. class Log {
  6. public:
  7. Log() = default;
  8. Log(const Log&) = delete;
  9.  
  10. ~Log() {
  11. cout << this << " dtor" << endl;
  12. cout << stream_.str() << endl;
  13. }
  14.  
  15. template <class T>
  16. Log& operator<<(const T& info) {
  17. cout << this << " <<" << endl;
  18. stream_ << info;
  19. return *this;
  20. }
  21.  
  22. private:
  23. stringstream stream_;
  24. };
  25.  
  26. int main() {
  27. [] {
  28. Log log;
  29. log << "A";
  30. return log;
  31. } () << "B";
  32.  
  33. return 0;
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In lambda function:
prog.cpp:30:11: error: use of deleted function 'Log::Log(const Log&)'
    return log;
           ^
prog.cpp:8:3: note: declared here
   Log(const Log&) = delete;
   ^
prog.cpp: In static member function 'static Log main()::<lambda()>::_FUN()':
prog.cpp:31:2: error: use of deleted function 'Log::Log(const Log&)'
  } () << "B";
  ^
prog.cpp:8:3: note: declared here
   Log(const Log&) = delete;
   ^
stdout
Standard output is empty