由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - c++ 里面 this pointer 是完全 un necessary 的吗?
相关主题
Is the order of initialization a, b, c or c, b, a?请问delete的问题
*(&b1)=b编译不过,b1=b可以,区别是?pointer to base class = new derived, what will happend??
又问几个c语言编程的题目copy constructor 问题
菜鸟请教smart pointerWhy this is a dangling pointer
question about Design Patterns大家觉得C++复杂在哪里?
C++ Q05: pointer to constant variable问一道brainbench上的问题
C++ Q93 - Q95 (转载)[c++] reference 真得不能bound to a second object 么?
delete this problemwhy copy assignment operator returns non-const type?
相关话题的讨论汇总
话题: pointer话题: un话题: assignment话题: necessary话题: 完全
进入Programming版参与讨论
1 (共1页)
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
4
还有operator ++()返回*this.
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

1 (共1页)
进入Programming版参与讨论
相关主题
why copy assignment operator returns non-const type?question about Design Patterns
C++ 中 myobject * a =new myobject[n] 的问题C++ Q05: pointer to constant variable
[合集] C# 面试问题讨论C++ Q93 - Q95 (转载)
operator() overloading 一问delete this problem
Is the order of initialization a, b, c or c, b, a?请问delete的问题
*(&b1)=b编译不过,b1=b可以,区别是?pointer to base class = new derived, what will happend??
又问几个c语言编程的题目copy constructor 问题
菜鸟请教smart pointerWhy this is a dangling pointer
相关话题的讨论汇总
话题: pointer话题: un话题: assignment话题: necessary话题: 完全