|
431 | 431 | \begin{note}
|
432 | 432 | The declaration of a class name takes effect immediately after the
|
433 | 433 | \grammarterm{identifier} is seen in the class definition or
|
434 |
| -\grammarterm{elaborated-type-specifier}. For example, |
| 434 | +\grammarterm{elaborated-type-specifier}. |
| 435 | +\begin{example} |
435 | 436 | \begin{codeblock}
|
436 | 437 | class A * A;
|
437 | 438 | \end{codeblock}
|
438 | 439 | first specifies \tcode{A} to be the name of a class and then redefines
|
439 | 440 | it as the name of a pointer to an object of that class. This means that
|
440 | 441 | the elaborated form \keyword{class} \tcode{A} must be used to refer to the
|
441 | 442 | class. Such artistry with names can be confusing and is best avoided.
|
| 443 | +\end{example} |
442 | 444 | \end{note}
|
443 | 445 |
|
444 | 446 | \pnum
|
|
948 | 950 | A member function can be declared (but not defined) using a typedef for
|
949 | 951 | a function type. The resulting member function has exactly the same type
|
950 | 952 | as it would have if the function declarator were provided explicitly,
|
951 |
| -see~\ref{dcl.fct}. For example, |
952 |
| - |
| 953 | +see~\ref{dcl.fct} and \ref{temp.arg}. |
| 954 | +\begin{example} |
953 | 955 | \begin{codeblock}
|
954 | 956 | typedef void fv();
|
955 | 957 | typedef void fvc() const;
|
|
962 | 964 | fv S::* pmfv2 = &S::memfunc2;
|
963 | 965 | fvc S::* pmfv3 = &S::memfunc3;
|
964 | 966 | \end{codeblock}
|
965 |
| - |
966 |
| -Also see~\ref{temp.arg}. |
| 967 | +\end{example} |
967 | 968 | \end{note}
|
968 | 969 |
|
969 | 970 | \rSec2[class.mfct.non.static]{Non-static member functions}%
|
|
2221 | 2222 | Such use of explicit placement and destruction of objects can be necessary
|
2222 | 2223 | to cope with dedicated hardware resources and for writing memory management
|
2223 | 2224 | facilities.
|
2224 |
| -For example, |
| 2225 | +\begin{example} |
2225 | 2226 | \begin{codeblock}
|
2226 | 2227 | void* operator new(std::size_t, void* p) { return p; }
|
2227 | 2228 | struct X {
|
|
2237 | 2238 | p->X::~X(); // cleanup
|
2238 | 2239 | }
|
2239 | 2240 | \end{codeblock}
|
| 2241 | +\end{example} |
2240 | 2242 | \end{note}
|
2241 | 2243 |
|
2242 | 2244 | \pnum
|
|
2866 | 2868 | refers to an object of class type with a virtual destructor,
|
2867 | 2869 | because the deallocation function is chosen by the destructor
|
2868 | 2870 | of the dynamic type of the object, the effect is the same in that case.
|
2869 |
| -For example, |
| 2871 | +\begin{example} |
2870 | 2872 | \begin{codeblock}
|
2871 | 2873 | struct B {
|
2872 | 2874 | virtual ~B();
|
|
2902 | 2904 | and its storage is deallocated
|
2903 | 2905 | by \tcode{E::operator delete()},
|
2904 | 2906 | due to the virtual destructor.
|
| 2907 | +\end{example} |
2905 | 2908 | \end{note}
|
2906 | 2909 | \begin{note}
|
2907 | 2910 | Virtual destructors have no effect on the deallocation function actually
|
|
2910 | 2913 | of a
|
2911 | 2914 | \grammarterm{delete-expression}
|
2912 | 2915 | refers to an array of objects of class type.
|
2913 |
| -For example, |
| 2916 | +\begin{example} |
2914 | 2917 | \begin{codeblock}
|
2915 | 2918 | struct B {
|
2916 | 2919 | virtual ~B();
|
|
2928 | 2931 | delete[] bp; // undefined behavior
|
2929 | 2932 | }
|
2930 | 2933 | \end{codeblock}
|
| 2934 | +\end{example} |
2931 | 2935 | \end{note}
|
2932 | 2936 |
|
2933 | 2937 | \pnum
|
|
4242 | 4246 | Because access control applies to the declarations named, if access control is applied to a
|
4243 | 4247 | \grammarterm{typedef-name}, only the accessibility of the typedef or alias declaration itself is considered.
|
4244 | 4248 | The accessibility of the entity referred to by the \grammarterm{typedef-name} is not considered.
|
4245 |
| -For example, |
4246 |
| - |
| 4249 | +\begin{example} |
4247 | 4250 | \begin{codeblock}
|
4248 | 4251 | class A {
|
4249 | 4252 | class B { };
|
|
4256 | 4259 | A::B y; // access error, \tcode{A::B} is private
|
4257 | 4260 | }
|
4258 | 4261 | \end{codeblock}
|
| 4262 | +\end{example} |
4259 | 4263 | \end{note}
|
4260 | 4264 |
|
4261 | 4265 | \pnum
|
|
4520 | 4524 | a conversion from a pointer to a derived class to a pointer
|
4521 | 4525 | to an inaccessible base class can be ill-formed if an implicit conversion
|
4522 | 4526 | is used, but well-formed if an explicit cast is used.
|
4523 |
| -For example, |
4524 |
| - |
| 4527 | +\begin{example} |
4525 | 4528 | \begin{codeblock}
|
4526 | 4529 | class B {
|
4527 | 4530 | public:
|
|
4546 | 4549 | bp2->mi = 3; // OK, access through a pointer to \tcode{B}.
|
4547 | 4550 | }
|
4548 | 4551 | \end{codeblock}
|
| 4552 | +\end{example} |
4549 | 4553 | \end{note}
|
4550 | 4554 |
|
4551 | 4555 | \pnum
|
|
0 commit comments