struct Foo { int i; }; Foo create_foo() { return { 42 }; } int main() { Foo& my_foo = create_foo(); my_foo.i = 33; // Undefined behaviour! }
Standard input is empty
prog.cpp: In function 'int main()': prog.cpp:13:26: error: invalid initialization of non-const reference of type 'Foo&' from an rvalue of type 'Foo' Foo& my_foo = create_foo(); ^
Standard output is empty