r****t 发帖数: 10904 | 1 以前一直不自觉的用,如果所有 unqualified-id 都默认是通过 this pointer, 是不
是 this pointer 是完全不必要的? | X****r 发帖数: 3557 | 2 还有其它的用途,比如operator=需要返回*this
【在 r****t 的大作中提到】 : 以前一直不自觉的用,如果所有 unqualified-id 都默认是通过 this pointer, 是不 : 是 this pointer 是完全不必要的?
| r****t 发帖数: 10904 | 3 对啊,忘了这一茬。
【在 X****r 的大作中提到】 : 还有其它的用途,比如operator=需要返回*this
| z****e 发帖数: 2024 | | O*******d 发帖数: 20343 | 5 operator=需要检查right hand是否是自己。 需要用到this. | z****e 发帖数: 2024 | 6 actually, operator= does not have to do self assignment check.
whatever passed in op=, just call the copy constructor, then assign *this to
the result of the copy constructor.
in this case, even the passed in object is itself, it will copy itself and
do the assignment.
The advantage is that, no self assignment check for each op=, which improves
the efficiency.
in real practice, very unlikely, op= take itself as the argument.
【在 O*******d 的大作中提到】 : operator=需要检查right hand是否是自己。 需要用到this.
| t****t 发帖数: 6806 | 7 唉, 这好象没什么长进啊.
to
improves
【在 z****e 的大作中提到】 : actually, operator= does not have to do self assignment check. : whatever passed in op=, just call the copy constructor, then assign *this to : the result of the copy constructor. : in this case, even the passed in object is itself, it will copy itself and : do the assignment. : The advantage is that, no self assignment check for each op=, which improves : the efficiency. : in real practice, very unlikely, op= take itself as the argument.
| r****t 发帖数: 10904 | 8 item 11 in "effective", 说绝对了一点吧。
【在 t****t 的大作中提到】 : 唉, 这好象没什么长进啊. : : to : improves
|
|