Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

reference

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?

like image 846
huio Avatar asked Jan 29 '10 16:01

huio


1 Answers

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.

like image 121
James McNellis Avatar answered Sep 27 '22 23:09

James McNellis