You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
r1 is a int&, while v2 is a const int.
Why it is legel?
The text was updated successfully, but these errors were encountered: