int f() { return 42; } // returns by value int main() { const int& cir = f(); // ok: const ref to temporary object int& ir = f(); // snytax error: non-const ref to temporary object }
Standard input is empty
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 ^
Standard output is empty