fork download
  1. int f() { return 42; } // returns by value
  2.  
  3. int main()
  4. {
  5. const int& cir = f(); // ok: const ref to temporary object
  6. int& ir = f(); // snytax error: non-const ref to temporary object
  7. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:6:22: error: invalid initialization of non-const reference of type 'int&' from an rvalue of type 'int'
         int& ir  = f();  // snytax error: non-const ref to temporary object
                      ^
stdout
Standard output is empty