-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconst_class.tex
65 lines (52 loc) · 1.38 KB
/
const_class.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
\subsection{const class}
\begin{frame}[fragile]{const member funktionen}
\begin{block}{const als Absicherung}
\lstinputlisting[xleftmargin=3em, basicstyle=\tiny]{cpp-code/const-safeguard.cpp}
\end{block}
\end{frame}
\begin{frame}[fragile]{const member funktionen}
\begin{block}{const als Veränderungsschutz}
\begin{small}
\begin{lstlisting}[language=C++]
void drucker(const MyClass& arg)
{
std::cout << arg.getInt() << std::endl;
arg.setInt(99); // wird nicht kompiliert
}
void testfun(MyClass& arg)
{
std::cout << arg.getInt() << std::endl;
arg.setInt(99);
}
void myfun()
{
MyClass pObj;
pObj.setInt(42);
testfun(pObj);
drucker(pObj);
}
\end{lstlisting}
\end{small}
\end{block}
\end{frame}
\begin{frame}[fragile]{const overloading}
\begin{block}{const overloading}
\begin{small}
\begin{lstlisting}[language=C++]
class MyClass
{
private:
int * m_iBlub;
public:
// sinnvoller overload
const int * get() const { return m_iBlub; }
int * get() { return m_iBlub; }
// Rueckgabetyp kann frei gewaehlt werden
// Sinnhaftigkeit ist allerdings fragwuerdig
std::string seltsam() { return "blubber"; }
double*** seltsam() const { return NULL; }
};
\end{lstlisting}
\end{small}
\end{block}
\end{frame}