Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ex2.31 #163

Open
hhdidid opened this issue Apr 3, 2019 · 3 comments
Open

ex2.31 #163

hhdidid opened this issue Apr 3, 2019 · 3 comments

Comments

@hhdidid
Copy link

hhdidid commented Apr 3, 2019

r1 is a int&, while v2 is a const int.
Why it is legel?

r1 = v2; // legal, top-level const in v2 is ignored.

@KshZh
Copy link

KshZh commented Aug 21, 2019

This is assignment rather than binding.

@mental1104
Copy link

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.

@Fanloe
Copy link

Fanloe commented Nov 28, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants