开发者

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.

Which one this code:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜