Regarding references

it is said that references once intialized to one object cannot refer to another object

i wrote a code like

class A
{
// some data members and functions

}
int main()
{
A a,b;
A &ref=a;
ref=b; //but this works fine


}

please explain me the above statement with code and also tell me why it cant refer to another objects


thanks in advance
Last edited on
ref=b; //but this works fine here you are not rebinding the reference, you are changing the object, reference points to.
This line and (a=b;) are absolutely equivalent.
Last edited on
Topic archived. No new replies allowed.