Assigning references
Consider the following declarations:
Object *a;
Object *b;
There are two ways of assigning a
to b
, by value or by reference:
a = b; // by reference
*a = *b; // by value
If the declarations are:
Object &a;
Object &b;
(I know its not possible to declare them without initializing them, its just开发者_开发技巧 to show the types)
There are two ways of assigning a
to b
too, just like with pointers, by reference or by value.
a = b;
is going to do? Is it possible to make it do the opposite one? (with a different syntax?)
That overwrites the object referred to.
And no, it is not possible to rebind a reference so that it refers to a different object. If you need to do that, use a pointer instead.
精彩评论