Why does this code fail to compile?
double d ;
int & i1 = d // Compilation FAILS
While this one does?
double d ;
const int & i = d // Compilation Succeeds
Please, I am interested in knowing what was in mind of C++ designers that they allowed one behavior while disallowed another.
I know in either case it’s immoral, independent of technically possible or not.
Also FYI I am using GCC on mac with “-O0 -g3 -Wall -c -fmessage-length=0”
Because it creates a temporary
intwhere the double is converted, and mutable references cannot bind to temporaries, whereasconstones can.The problem with allowing mutable references to bind to temporaries is relatively clear.