11

Why is the this pointer in C++ a pointer and not a reference?

Are there use-cases that I'm missing that make "this" as a pointer more useful than a reference?

If not, are there any language design implications/considerations involved in having it as a pointer?

George Stocker
  • 57,289
  • 29
  • 176
  • 237
huio
  • 127
  • 3
  • 1
    Voted to re-open. As currently stated the question has an unambiguous answer -- which James McNellis posted. – Keith Thompson Dec 01 '12 at 02:59
  • @KeithThompson, I think people are too quick to close a question that they think can't be answered. If you want to volunteer an upvote for another here it is: http://stackoverflow.com/questions/13652006/why-accessing-to-class-variable-from-within-the-class-needs-self-in-python – Mark Ransom Dec 04 '12 at 03:20

1 Answers1

21

From Bjarne Stroustrup's C++ Style and Technique FAQ:

Why is this not a reference?

Because this was introduced into C++ (really into C with Classes) before references were added. Also, I chose this to follow Simula usage, rather than the (later) Smalltalk use of self.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
James McNellis
  • 348,265
  • 75
  • 913
  • 977