ex2.31
r1 is a int&, while v2 is a const int. Why it is legel?
r1 = v2; // legal, top-level const in v2 is ignored.
This is assignment rather than binding.
Same question, the example in the book says int &r = ci (const int ci = 42), is illegal, which is same as "r1 = v2", so I think "r1 = v2" should be illegal.
At first, I thought it's illegal. Then I wrote a program to verify it: const int v2 = 0; int &r1 = v2; This is illegal; Then I find that r1 has been bound to v1, so r1 represents v1 which is an int type. The appropriate program is: int v1 = 0; const int v2 = 0; int &r1 = v1; r1 = v2; That's right. It's legal as an assignment.