The situation of my interest is
const int &n1 = 123;
const int &n2 = 123;
I know it is something as if the literal 123
is the parameter for initializing a temporary int
and const
is just a boring compile time check, but I want to know the reason why distinct temporaries are needed in this case, instead of n1
and n2
both having the same temporary.
I know the rule exists but do not know why this rule exists.