Possible Duplicates:
Why ‘this’ is a pointer and not a reference?
SAFE Pointer to a pointer (well reference to a reference) in C#
The this
keyword in C++ gets a pointer to the object I currently am.
My question is why is the type of this
a pointer type and not a reference type.
Are there any conditions under which the this
keyword would be NULL
?
My immediate thought would be in a static function, but Visual C++ at least is smart enough to spot this and report static member functions do not have 'this' pointers
. Is this in the standard?
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".
this (C# Reference) The this keyword refers to the current instance of the class and is also used as a modifier of the first parameter of an extension method.
There are two kinds of references: lvalue references which refer to a named variable and rvalue references which refer to a temporary object.
See Stroustrup's 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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With