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