forked from hsf-training/cpluspluscourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic.tex
43 lines (39 loc) · 1.06 KB
/
static.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
\subsection[static]{Static members}
\begin{frame}[fragile]
\frametitlecpp[98]{Static members}
\begin{block}{Concept}
\begin{itemize}
\item members attached to a class rather than to an object
\item usable with or without an instance of the class
\item identified by the \cppinline{static} keyword
\end{itemize}
\end{block}
\vspace{-1\baselineskip}
\begin{overprint}
\onslide<1>
\begin{exampleblock}{Static.hpp}
\begin{cppcode}
class Text {
public:
static std::string upper(std::string);
private:
static int callsToUpper; // add `inline` in C++17
};
\end{cppcode}
\end{exampleblock}
\onslide<2>
\begin{exampleblock}{Static.cpp}
\begin{cppcode}
#include "Static.hpp"
int Text::callsToUpper = 0; // required before C++17
std::string Text::upper(std::string lower) {
callsToUpper++;
// convert lower to upper case
// return ...;
}
std::string uppers = Text::upper("my text");
// now Text::callsToUpper is 1
\end{cppcode}
\end{exampleblock}
\end{overprint}
\end{frame}