9

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]

Community
  • 1
  • 1
  • I'm pretty sure it's a dupe but I'm having similar trouble finding it... – Cogwheel Jul 01 '10 at 22:38
  • 3
    Possible duplicate of [Why 'this' is a pointer and not a reference?](http://stackoverflow.com/questions/645994/why-this-is-a-pointer-and-not-a-reference) - found via [google](http://www.google.com/search?q=site%3Astackoverflow.com+c%2B%2B+why+is+this+not+a+reference). – Georg Fritzsche Jul 01 '10 at 22:48

2 Answers2

6

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.

Andy Thomas
  • 84,978
  • 11
  • 107
  • 151
3

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

syockit
  • 5,747
  • 1
  • 24
  • 33
Cogwheel
  • 22,781
  • 4
  • 49
  • 67