fork download
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4.  
  5. class Foo
  6. {
  7. public:
  8. Foo()
  9. : x(0)
  10. {
  11. std::cout << "C-Tor " << x << std::endl;
  12. }
  13.  
  14. ~Foo()
  15. {
  16. std::cout << "D-Tor " << x << std::endl;
  17. }
  18.  
  19. int x;
  20. };
  21.  
  22. void bar(Foo & f)
  23. {
  24. f.x = 5;
  25. std::cout << "Funktion " << f.x << std::endl;
  26. }
  27.  
  28. int main()
  29. {
  30. {
  31. std::cout << "---------------" << std::endl;
  32. bar(Foo());
  33. std::cout << "---------------" << std::endl;
  34. }
  35. return 0x0;
  36. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:32:19: error: invalid initialization of non-const reference of type ‘Foo&’ from an rvalue of type ‘Foo’
prog.cpp:22:6: error: in passing argument 1 of ‘void bar(Foo&)’
stdout
Standard output is empty