Skip to content

[classes] Turn ad-hoc examples into proper examples #7125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions source/classes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,16 @@
\begin{note}
The declaration of a class name takes effect immediately after the
\grammarterm{identifier} is seen in the class definition or
\grammarterm{elaborated-type-specifier}. For example,
\grammarterm{elaborated-type-specifier}.
\begin{example}
\begin{codeblock}
class A * A;
\end{codeblock}
first specifies \tcode{A} to be the name of a class and then redefines
it as the name of a pointer to an object of that class. This means that
the elaborated form \keyword{class} \tcode{A} must be used to refer to the
class. Such artistry with names can be confusing and is best avoided.
\end{example}
\end{note}

\pnum
Expand Down Expand Up @@ -948,8 +950,8 @@
A member function can be declared (but not defined) using a typedef for
a function type. The resulting member function has exactly the same type
as it would have if the function declarator were provided explicitly,
see~\ref{dcl.fct}. For example,

see~\ref{dcl.fct} and \ref{temp.arg}.
\begin{example}
\begin{codeblock}
typedef void fv();
typedef void fvc() const;
Expand All @@ -962,8 +964,7 @@
fv S::* pmfv2 = &S::memfunc2;
fvc S::* pmfv3 = &S::memfunc3;
\end{codeblock}

Also see~\ref{temp.arg}.
\end{example}
\end{note}

\rSec2[class.mfct.non.static]{Non-static member functions}%
Expand Down Expand Up @@ -2221,7 +2222,7 @@
Such use of explicit placement and destruction of objects can be necessary
to cope with dedicated hardware resources and for writing memory management
facilities.
For example,
\begin{example}
\begin{codeblock}
void* operator new(std::size_t, void* p) { return p; }
struct X {
Expand All @@ -2237,6 +2238,7 @@
p->X::~X(); // cleanup
}
\end{codeblock}
\end{example}
\end{note}

\pnum
Expand Down Expand Up @@ -2866,7 +2868,7 @@
refers to an object of class type with a virtual destructor,
because the deallocation function is chosen by the destructor
of the dynamic type of the object, the effect is the same in that case.
For example,
\begin{example}
\begin{codeblock}
struct B {
virtual ~B();
Expand Down Expand Up @@ -2902,6 +2904,7 @@
and its storage is deallocated
by \tcode{E::operator delete()},
due to the virtual destructor.
\end{example}
\end{note}
\begin{note}
Virtual destructors have no effect on the deallocation function actually
Expand All @@ -2910,7 +2913,7 @@
of a
\grammarterm{delete-expression}
refers to an array of objects of class type.
For example,
\begin{example}
\begin{codeblock}
struct B {
virtual ~B();
Expand All @@ -2928,6 +2931,7 @@
delete[] bp; // undefined behavior
}
\end{codeblock}
\end{example}
\end{note}

\pnum
Expand Down Expand Up @@ -4242,8 +4246,7 @@
Because access control applies to the declarations named, if access control is applied to a
\grammarterm{typedef-name}, only the accessibility of the typedef or alias declaration itself is considered.
The accessibility of the entity referred to by the \grammarterm{typedef-name} is not considered.
For example,

\begin{example}
\begin{codeblock}
class A {
class B { };
Expand All @@ -4256,6 +4259,7 @@
A::B y; // access error, \tcode{A::B} is private
}
\end{codeblock}
\end{example}
\end{note}

\pnum
Expand Down Expand Up @@ -4520,8 +4524,7 @@
a conversion from a pointer to a derived class to a pointer
to an inaccessible base class can be ill-formed if an implicit conversion
is used, but well-formed if an explicit cast is used.
For example,

\begin{example}
\begin{codeblock}
class B {
public:
Expand All @@ -4546,6 +4549,7 @@
bp2->mi = 3; // OK, access through a pointer to \tcode{B}.
}
\end{codeblock}
\end{example}
\end{note}

\pnum
Expand Down
Loading