fork download
  1. #include <iostream>
  2.  
  3. // Invalid example:
  4. void foo(int& x)
  5. {
  6. std::cout << x << std::endl;
  7. }
  8.  
  9. int main()
  10. {
  11. // not legal; can't bind a temporary to a non-const reference (because what if foo() changed it?)
  12. foo(7 * 6);
  13. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:12: error: invalid initialization of non-const reference of type ‘int&’ from a temporary of type ‘int’
prog.cpp:4: error: in passing argument 1 of ‘void foo(int&)’
stdout

Standard output is empty