fork download
  1. #include <iostream>
  2.  
  3. class X {
  4. public:
  5. X() {
  6. std::cout << "X constructor called\n";
  7. }
  8.  
  9. X(const X &other) = delete;
  10.  
  11. ~X() {
  12. std::cout << "X destructor called\n";
  13. }
  14. };
  15.  
  16.  
  17. X create_x() {
  18. X x;
  19. return x;
  20. }
  21.  
  22. int main() {
  23. auto x = create_x();
  24. return 0;
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'X create_x()':
prog.cpp:19:12: error: use of deleted function 'X::X(const X&)'
     return x;
            ^
prog.cpp:9:5: note: declared here
     X(const X &other) = delete;
     ^
prog.cpp: In function 'int main()':
prog.cpp:23:23: error: use of deleted function 'X::X(const X&)'
     auto x = create_x();
                       ^
prog.cpp:9:5: note: declared here
     X(const X &other) = delete;
     ^
stdout
Standard output is empty