I know I'm not allowed to write long& const x
. But why not? Theoretically I could have a constant reference to x. I just wouldn't be able to set the reference to another address.
Why is it forbiden in C++?
Edit: I know there is something I don't understand, but I can assign a reference to another variable. This piece of code works:
#include <iostream>
int main()
{
int a = 1, b = 2;
int & x = a;
x = b;
return 0;
}
But this is a contradiction to what you are saing.