Today I saw this code:
int a = 0; const decltype((a)) x = 10;
I see why the correct code is correct, but I do not understand why the wrong code is incorrect.
I tested it and just found it a little weird.
const decltype((a)) x = 10; Should this be the correct definition of const int& ? But it does not compile! error: non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int' .
I changed it to const decltype((a)) x = a; , then it compiles.
Well, is x link const? No, I found this to be a non-constant link. I can change the value of a through x .
Why didn't you use the const modifier?
source share