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
  • 48,681
  • 42
  • 161
  • 257

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
  • 7,722
  • 3
  • 31
  • 42
Prasoon Saurav
  • 88,492
  • 46
  • 234
  • 343
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
  • 196,304
  • 62
  • 355
  • 262
Alexander Rafferty
  • 6,034
  • 2
  • 31
  • 55