|
1009 | 1009 | \end{example}
|
1010 | 1010 |
|
1011 | 1011 | \pnum
|
| 1012 | +\indextext{member function!const}% |
| 1013 | +\indextext{member function!volatile}% |
| 1014 | +\indextext{member function!const volatile}% |
1012 | 1015 | A non-static member function may be declared \tcode{const},
|
1013 | 1016 | \tcode{volatile}, or \tcode{const} \tcode{volatile}. These
|
1014 | 1017 | \grammarterm{cv-qualifier}{s} affect the type of the \tcode{this}
|
1015 | 1018 | pointer~(\ref{class.this}). They also affect the function
|
1016 | 1019 | type~(\ref{dcl.fct}) of the member function; a member function declared
|
1017 |
| -\tcode{const} is a \term{const} member function, a member function |
1018 |
| -declared \tcode{volatile} is a \term{volatile} member function and a |
| 1020 | +\tcode{const} is a \defn{const member function}, a member function |
| 1021 | +declared \tcode{volatile} is a \defn{volatile member function} and a |
1019 | 1022 | member function declared \tcode{const} \tcode{volatile} is a
|
1020 |
| -\term{const volatile} member function. |
| 1023 | +\defn{const volatile member function}. |
1021 | 1024 | \begin{example}
|
1022 | 1025 |
|
1023 | 1026 | \begin{codeblock}
|
|
1027 | 1030 | };
|
1028 | 1031 | \end{codeblock}
|
1029 | 1032 |
|
1030 |
| -\tcode{X::g} is a \tcode{const} member function and \tcode{X::h} is a |
1031 |
| -\tcode{const} \tcode{volatile} member function. |
| 1033 | +\tcode{X::g} is a const member function and \tcode{X::h} is a |
| 1034 | +const volatile member function. |
1032 | 1035 | \end{example}
|
1033 | 1036 |
|
1034 | 1037 | \pnum
|
|
1050 | 1053 | \indextext{\idxcode{this}!type of}%
|
1051 | 1054 | The type of \tcode{this} in a member function of a class \tcode{X} is
|
1052 | 1055 | \tcode{X*}.
|
1053 |
| -\indextext{member function!\idxcode{const}}% |
1054 | 1056 | If the member function is declared \tcode{const}, the type of
|
1055 | 1057 | \tcode{this} is \tcode{const} \tcode{X*},
|
1056 |
| -\indextext{member function!\idxcode{volatile}}% |
1057 | 1058 | if the member function is declared \tcode{volatile}, the type of
|
1058 | 1059 | \tcode{this} is \tcode{volatile} \tcode{X*}, and if the member function
|
1059 | 1060 | is declared \tcode{const} \tcode{volatile}, the type of \tcode{this} is
|
1060 | 1061 | \tcode{const} \tcode{volatile} \tcode{X*}.
|
1061 |
| -\indextext{member function!\idxcode{const}}% |
1062 |
| -\begin{note} Thus in a \tcode{const} member function, the object for which the function is |
1063 |
| -called is accessed through a \tcode{const} access path. \end{note} |
| 1062 | +\begin{note} Thus in a const member function, the object for which the function is |
| 1063 | +called is accessed through a const access path. \end{note} |
1064 | 1064 | \begin{example}
|
1065 | 1065 |
|
1066 | 1066 | \begin{codeblock}
|
|
1076 | 1076 |
|
1077 | 1077 | The \tcode{a++} in the body of \tcode{s::h} is ill-formed because it
|
1078 | 1078 | tries to modify (a part of) the object for which \tcode{s::h()} is
|
1079 |
| -called. This is not allowed in a \tcode{const} member function because |
| 1079 | +called. This is not allowed in a const member function because |
1080 | 1080 | \tcode{this} is a pointer to \tcode{const}; that is, \tcode{*this} has
|
1081 | 1081 | \tcode{const} type.
|
1082 | 1082 | \end{example}
|
1083 | 1083 |
|
1084 | 1084 | \pnum
|
1085 | 1085 | Similarly, \tcode{volatile} semantics~(\ref{dcl.type.cv}) apply in
|
1086 |
| -\tcode{volatile} member functions when accessing the object and its |
| 1086 | +volatile member functions when accessing the object and its |
1087 | 1087 | non-static data members.
|
1088 | 1088 |
|
1089 | 1089 | \pnum
|
|
1102 | 1102 | \end{codeblock}
|
1103 | 1103 |
|
1104 | 1104 | The call \tcode{y.g()} is ill-formed because \tcode{y} is \tcode{const}
|
1105 |
| -and \tcode{s::g()} is a non-\tcode{const} member function, that is, |
| 1105 | +and \tcode{s::g()} is a non-const member function, that is, |
1106 | 1106 | \tcode{s::g()} is less-qualified than the object-expression \tcode{y}.
|
1107 | 1107 | \end{example}
|
1108 | 1108 |
|
|
0 commit comments