Turn up compiler warnings to level 4. I suspect you will get a warning, since this is a Microsoft extension (accepting a non-const reference to a temporary).
Printable View
Turn up compiler warnings to level 4. I suspect you will get a warning, since this is a Microsoft extension (accepting a non-const reference to a temporary).
I can also do this with no warnings:
Code:class X
{
int n;
public:
X() {}
void set_n(int nn) {n = nn;}
};
X f1() {X x; return x;}
void f2(X& x) {X& y = x; y.set_n(5);}
int main() { f2(f1()); }
Warning 1 warning C4239: nonstandard extension used : 'argument' : conversion from 'X' to 'X &'
This is what you should see with the highest warning level.
If you select to disable language extensions, it will yield a compile error.