If I did not read "C ++ programming ideology", I am afraid that I will not know the member pointer today, which has really opened my eyes. In my understanding, the normal Pointer Points to the address relative to the entire memory space, and the member pointer does not contain the real address, it actually represents the relative position of a member within its class range. A small program can explain the usage of member pointers.
# Include
<Iostream>
Using
Namespace
STD
;
Class
C
{
Public
:
Int
I
,
J
,
K
;
Void
F
()
{
Cout
<
I
<
''
<
J
<
''
<
K
<
'/N'
;
}
};
Int
Main
()
{
C
C
;
C
.
I
=
1
;
C
.
J
=
2
;
C
.
K
=
3
;
C
*
PC
=
&
C
;
Int
C
::*
PM
=
&
C
::
J
;
Cout
<
C
.
*
PM
<
PC
-> *
PM
<
'/N'
;
Void
(C
::*
PMF
) () =
&
C
::
F
;
(C
.
*
PMF
)();
(PC
-> *
PMF
)();
Return
0
;
}
The code output is 22 and 1 2 3. PM is defined as a pointer to Class C member J. When PM is applied to object C, the value of member J of the C object is output. Of course, it cannot be used for private members. PMF points to the member function f of C. When PMF is called on Object C, the member function f is called. The principle is not complex, but it is unclear where such a mechanism is applicable.