会让“这个”变成“这个”吗?回想起来,引用而不是指针更好?
可能的重复:
为什么“this”是指针而不是引用?
除了历史语言决定之外,C++ 中的 this
是否有任何理由成为指针而不是引用?这感觉有点奇怪,因为例如复制构造函数或赋值运算符都接受“that
”的引用,而不是指针。
[老实说,我找不到这个问题,尽管它确实感觉可能是重复的]
Possible Duplicate:
Why ‘this’ is a pointer and not a reference?
Is there any reason for this
in C++ to be a pointer rather than a reference other than historical language decision? It feels a tad strange given that e.g. copy constructor or assignment operators both accept reference to "that
", not a pointer.
[I honestly couldn't find this question, though it does feel like a possible duplicate]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 Bjarne Stroustrup 的“C++ 的设计和演化”,Addison-Wesley,1994 年,第 39-40 页:
From Bjarne Stroustrup's "The Design and Evolution of C++", Addison-Wesley, 1994, pp 39-40:
当
this
出现时,语言中不存在引用创建的。References didn't exist in the language when
this
was created.