mirror of
https://github.com/pkivolowitz/asm_book.git
synced 2026-06-21 02:26:59 +08:00
improved text
This commit is contained in:
parent
7c896ef362
commit
144acfb9d6
1 changed files with 8 additions and 9 deletions
|
|
@ -6,18 +6,17 @@ using. The exception to *this*, of course, are methods which are declared
|
||||||
as `static` which do *not* know which specific instance you are
|
as `static` which do *not* know which specific instance you are
|
||||||
referring to - `static` methods are instance-agnostic.
|
referring to - `static` methods are instance-agnostic.
|
||||||
|
|
||||||
Like many of the cool features of C++, *this* seemingly magical
|
Like many of the cool features of C++, this seemingly magical
|
||||||
self-awareness is accomplished by slight-of-hand. In *this* chapter, we
|
self-awareness of which instance a non-static method is called with, is
|
||||||
examine how *this* is done.
|
accomplished by slight-of-hand.
|
||||||
|
|
||||||
In case the italics used up to now where ever the word *this* has been
|
|
||||||
used, the slight-of-hand involves the `this` pointer.
|
|
||||||
|
|
||||||
## `this` pointer
|
## `this` pointer
|
||||||
|
|
||||||
Every non-static method call employs a hidden first parameter. This
|
Every non-static method call employs a hidden first parameter. That's
|
||||||
parameter is the `this` pointer which points to the specific instance
|
it. That's the slight of hand. The hidden argument is the `this`
|
||||||
of the class being used.
|
pointer. It points to the base address of the class or struct. Then, the
|
||||||
|
particular members of the right instance, are accessed the same way as
|
||||||
|
any struct basing memory addresses off a pointer.
|
||||||
|
|
||||||
Here is the [source code](./this.cpp) to our test harness:
|
Here is the [source code](./this.cpp) to our test harness:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue