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?

2
  • 1
    Voted to re-open. As currently stated the question has an unambiguous answer -- which James McNellis posted. Commented Dec 1, 2012 at 2: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: stackoverflow.com/questions/13652006/… Commented Dec 4, 2012 at 3:20

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.