开发者

Would making 'this' a reference rather than a pointer be better in retrospect? [duplicate]

This question already has answers here: Closed 12 years ago.

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]


From Bjarne Stroustrup's "The Design and Evolution of C++", Addison-Wesley, 1994, pp 39-40:

Sometimes, people ask why this is a pointer rather than a reference and why it is called this rather than self. When this was introduced into C with Classes, the language didn't have references, and C++ borrows its terminology from Simula rather than Smalltalk.


References didn't exist in the language when this was created.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜