10

Possible Duplicate:
Why 'this' is a pointer and not a reference?

Why is this a pointer, rather rhan reference? Can it ever be NULL?

Community
  • 1
  • 1
Anycorn
  • 50,217
  • 42
  • 167
  • 261

2 Answers2

7

Why is "this" not a reference?

See Bjarne's answer here

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".

Waqar
  • 8,558
  • 4
  • 35
  • 43
Prasoon Saurav
  • 91,295
  • 49
  • 239
  • 345
2

Why is this a pointer?

Because it is, and it is just the way the programming language was designed. (I think it is also because it was left over from C, but I am not sure).

rather than a reference?

If you need a this reference, use *this.

Can it never be NULL?

...no. How could it be?

Cristian
  • 198,401
  • 62
  • 356
  • 264
Alexander Rafferty
  • 6,134
  • 4
  • 33
  • 55