#include <iostream>using namespace std; struct A{ int x; A(); ~A(); A(int);};A::~A() {}A::A() : x(0) {}A::A(int _x) : x(_x) {} void func(A &a){ a.x=10; } int main() { A a; func(a); func(A()); return 0;}
Standard input is empty
prog.cpp: In function 'int main()': prog.cpp:26:13: error: invalid initialization of non-const reference of type 'A&' from an rvalue of type 'A' func(A()); ^ prog.cpp:15:6: note: initializing argument 1 of 'void func(A&)' void func(A &a) ^
Standard output is empty
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!