Skip to content

Commit a249f9f

Browse files
authored
[classes] Turn ad-hoc examples into proper examples (#7125)
1 parent ecb0716 commit a249f9f

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

source/classes.tex

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,16 @@
431431
\begin{note}
432432
The declaration of a class name takes effect immediately after the
433433
\grammarterm{identifier} is seen in the class definition or
434-
\grammarterm{elaborated-type-specifier}. For example,
434+
\grammarterm{elaborated-type-specifier}.
435+
\begin{example}
435436
\begin{codeblock}
436437
class A * A;
437438
\end{codeblock}
438439
first specifies \tcode{A} to be the name of a class and then redefines
439440
it as the name of a pointer to an object of that class. This means that
440441
the elaborated form \keyword{class} \tcode{A} must be used to refer to the
441442
class. Such artistry with names can be confusing and is best avoided.
443+
\end{example}
442444
\end{note}
443445

444446
\pnum
@@ -948,8 +950,8 @@
948950
A member function can be declared (but not defined) using a typedef for
949951
a function type. The resulting member function has exactly the same type
950952
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}
953955
\begin{codeblock}
954956
typedef void fv();
955957
typedef void fvc() const;
@@ -962,8 +964,7 @@
962964
fv S::* pmfv2 = &S::memfunc2;
963965
fvc S::* pmfv3 = &S::memfunc3;
964966
\end{codeblock}
965-
966-
Also see~\ref{temp.arg}.
967+
\end{example}
967968
\end{note}
968969

969970
\rSec2[class.mfct.non.static]{Non-static member functions}%
@@ -2221,7 +2222,7 @@
22212222
Such use of explicit placement and destruction of objects can be necessary
22222223
to cope with dedicated hardware resources and for writing memory management
22232224
facilities.
2224-
For example,
2225+
\begin{example}
22252226
\begin{codeblock}
22262227
void* operator new(std::size_t, void* p) { return p; }
22272228
struct X {
@@ -2237,6 +2238,7 @@
22372238
p->X::~X(); // cleanup
22382239
}
22392240
\end{codeblock}
2241+
\end{example}
22402242
\end{note}
22412243

22422244
\pnum
@@ -2866,7 +2868,7 @@
28662868
refers to an object of class type with a virtual destructor,
28672869
because the deallocation function is chosen by the destructor
28682870
of the dynamic type of the object, the effect is the same in that case.
2869-
For example,
2871+
\begin{example}
28702872
\begin{codeblock}
28712873
struct B {
28722874
virtual ~B();
@@ -2902,6 +2904,7 @@
29022904
and its storage is deallocated
29032905
by \tcode{E::operator delete()},
29042906
due to the virtual destructor.
2907+
\end{example}
29052908
\end{note}
29062909
\begin{note}
29072910
Virtual destructors have no effect on the deallocation function actually
@@ -2910,7 +2913,7 @@
29102913
of a
29112914
\grammarterm{delete-expression}
29122915
refers to an array of objects of class type.
2913-
For example,
2916+
\begin{example}
29142917
\begin{codeblock}
29152918
struct B {
29162919
virtual ~B();
@@ -2928,6 +2931,7 @@
29282931
delete[] bp; // undefined behavior
29292932
}
29302933
\end{codeblock}
2934+
\end{example}
29312935
\end{note}
29322936

29332937
\pnum
@@ -4242,8 +4246,7 @@
42424246
Because access control applies to the declarations named, if access control is applied to a
42434247
\grammarterm{typedef-name}, only the accessibility of the typedef or alias declaration itself is considered.
42444248
The accessibility of the entity referred to by the \grammarterm{typedef-name} is not considered.
4245-
For example,
4246-
4249+
\begin{example}
42474250
\begin{codeblock}
42484251
class A {
42494252
class B { };
@@ -4256,6 +4259,7 @@
42564259
A::B y; // access error, \tcode{A::B} is private
42574260
}
42584261
\end{codeblock}
4262+
\end{example}
42594263
\end{note}
42604264

42614265
\pnum
@@ -4520,8 +4524,7 @@
45204524
a conversion from a pointer to a derived class to a pointer
45214525
to an inaccessible base class can be ill-formed if an implicit conversion
45224526
is used, but well-formed if an explicit cast is used.
4523-
For example,
4524-
4527+
\begin{example}
45254528
\begin{codeblock}
45264529
class B {
45274530
public:
@@ -4546,6 +4549,7 @@
45464549
bp2->mi = 3; // OK, access through a pointer to \tcode{B}.
45474550
}
45484551
\end{codeblock}
4552+
\end{example}
45494553
\end{note}
45504554

45514555
\pnum

0 commit comments

Comments
 (0)