|
988 | 988 | \end{example}
|
989 | 989 |
|
990 | 990 | \pnum
|
| 991 | +\indextext{member function!const}% |
| 992 | +\indextext{member function!volatile}% |
| 993 | +\indextext{member function!const volatile}% |
991 | 994 | A non-static member function may be declared \tcode{const},
|
992 | 995 | \tcode{volatile}, or \tcode{const} \tcode{volatile}. These
|
993 | 996 | \grammarterm{cv-qualifier}{s} affect the type of the \tcode{this}
|
994 | 997 | pointer~(\ref{class.this}). They also affect the function
|
995 | 998 | type~(\ref{dcl.fct}) of the member function; a member function declared
|
996 |
| -\tcode{const} is a \term{const} member function, a member function |
997 |
| -declared \tcode{volatile} is a \term{volatile} member function and a |
| 999 | +\tcode{const} is a \defn{const member function}, a member function |
| 1000 | +declared \tcode{volatile} is a \defn{volatile member function} and a |
998 | 1001 | member function declared \tcode{const} \tcode{volatile} is a
|
999 |
| -\term{const volatile} member function. |
| 1002 | +\defn{const volatile member function}. |
1000 | 1003 | \begin{example}
|
1001 | 1004 |
|
1002 | 1005 | \begin{codeblock}
|
|
1006 | 1009 | };
|
1007 | 1010 | \end{codeblock}
|
1008 | 1011 |
|
1009 |
| -\tcode{X::g} is a \tcode{const} member function and \tcode{X::h} is a |
1010 |
| -\tcode{const} \tcode{volatile} member function. |
| 1012 | +\tcode{X::g} is a const member function and \tcode{X::h} is a |
| 1013 | +const volatile member function. |
1011 | 1014 | \end{example}
|
1012 | 1015 |
|
1013 | 1016 | \pnum
|
|
1029 | 1032 | \indextext{\idxcode{this}!type of}%
|
1030 | 1033 | The type of \tcode{this} in a member function of a class \tcode{X} is
|
1031 | 1034 | \tcode{X*}.
|
1032 |
| -\indextext{member function!\idxcode{const}}% |
1033 | 1035 | If the member function is declared \tcode{const}, the type of
|
1034 | 1036 | \tcode{this} is \tcode{const} \tcode{X*},
|
1035 |
| -\indextext{member function!\idxcode{volatile}}% |
1036 | 1037 | if the member function is declared \tcode{volatile}, the type of
|
1037 | 1038 | \tcode{this} is \tcode{volatile} \tcode{X*}, and if the member function
|
1038 | 1039 | is declared \tcode{const} \tcode{volatile}, the type of \tcode{this} is
|
1039 | 1040 | \tcode{const} \tcode{volatile} \tcode{X*}.
|
1040 |
| -\indextext{member function!\idxcode{const}}% |
1041 |
| -\begin{note} Thus in a \tcode{const} member function, the object for which the function is |
1042 |
| -called is accessed through a \tcode{const} access path. \end{note} |
| 1041 | +\begin{note} Thus in a const member function, the object for which the function is |
| 1042 | +called is accessed through a const access path. \end{note} |
1043 | 1043 | \begin{example}
|
1044 | 1044 |
|
1045 | 1045 | \begin{codeblock}
|
|
1055 | 1055 |
|
1056 | 1056 | The \tcode{a++} in the body of \tcode{s::h} is ill-formed because it
|
1057 | 1057 | tries to modify (a part of) the object for which \tcode{s::h()} is
|
1058 |
| -called. This is not allowed in a \tcode{const} member function because |
| 1058 | +called. This is not allowed in a const member function because |
1059 | 1059 | \tcode{this} is a pointer to \tcode{const}; that is, \tcode{*this} has
|
1060 | 1060 | \tcode{const} type.
|
1061 | 1061 | \end{example}
|
1062 | 1062 |
|
1063 | 1063 | \pnum
|
1064 | 1064 | Similarly, \tcode{volatile} semantics~(\ref{dcl.type.cv}) apply in
|
1065 |
| -\tcode{volatile} member functions when accessing the object and its |
| 1065 | +volatile member functions when accessing the object and its |
1066 | 1066 | non-static data members.
|
1067 | 1067 |
|
1068 | 1068 | \pnum
|
|
1081 | 1081 | \end{codeblock}
|
1082 | 1082 |
|
1083 | 1083 | The call \tcode{y.g()} is ill-formed because \tcode{y} is \tcode{const}
|
1084 |
| -and \tcode{s::g()} is a non-\tcode{const} member function, that is, |
| 1084 | +and \tcode{s::g()} is a non-const member function, that is, |
1085 | 1085 | \tcode{s::g()} is less-qualified than the object-expression \tcode{y}.
|
1086 | 1086 | \end{example}
|
1087 | 1087 |
|
|
0 commit comments