I’m having problems wrapping my head around this. I have a function
void foo(istream& input) {
input = cin;
}
This fails (I’m assuming because cin isn’t supposed to be “copyable”.
however, this works
void foo(istream& input) {
istream& baz = cin;
}
Is there a reason that I can get a reference to cin in baz but I cannot assign it to input?
Thanks
This syntax:
Doesn’t create a reference. it invokes the
operator=which is meant to copy things around.This syntax however:
defines a new reference variable.
The key point is that in C++ you can’t change a reference once you’ve declared it.
After the declaration the reference behaves as if it is the object referenced to itself. So using
operator=on it tries to copy into it.