Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5bf6194

Browse files
Small refinements for objectorientation chapter.
1 parent 3b54c58 commit 5bf6194

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

‎talk/objectorientation/advancedoo.tex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@
244244
\frametitlecpp[11]{{\texttt override} keyword}
245245
\begin{block}{Principle}
246246
\begin{itemize}
247-
\item when overriding a virtual method
248-
\item the \cppinline|override| keyword should be used
247+
\item when overriding a virtual method, the \cppinline|override| keyword should be used
249248
\item the \cppinline|virtual| keyword is then optional
250249
\end{itemize}
251250
\end{block}

‎talk/objectorientation/allocations.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
\item each thread in a process has its own stack
3838
\begin{itemize}
3939
\item allocations on the stack are thus ``thread private''
40-
\item and do not introduce any threadsafety issues
40+
\item and do not introduce any thread-safety issues
4141
\end{itemize}
4242
\end{itemize}
4343
\end{block}
@@ -77,7 +77,7 @@
7777
\item there is a single, shared heap per process
7878
\begin{itemize}
7979
\item allows to share data between threads
80-
\item introduces race conditions and threadsafety issues!
80+
\item introduces race conditions and thread-safety issues!
8181
\end{itemize}
8282
\end{itemize}
8383
\end{block}

‎talk/objectorientation/constructors.tex

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@
106106

107107
\begin{frame}[fragile]
108108
\frametitlecpp[98]{Class Constructors and Destructors}
109+
\begin{overprint}
110+
\onslide<1>
111+
\begin{cppcode}
112+
class Vector {
113+
public:
114+
Vector(int n);
115+
Vector(const Vector &other);
116+
~Vector();
117+
private:
118+
int len; int* data;
119+
};
120+
Vector::Vector(int n) : len(n) {
121+
data = new int[n];
122+
}
123+
124+
125+
126+
127+
Vector::~Vector() { delete[] data; }
128+
\end{cppcode}
129+
\onslide<2>
109130
\begin{cppcode}
110131
class Vector {
111132
public:
@@ -124,6 +145,8 @@
124145
}
125146
Vector::~Vector() { delete[] data; }
126147
\end{cppcode}
148+
149+
\end{overprint}
127150
\end{frame}
128151

129152
\begin{frame}[fragile]
@@ -266,8 +289,8 @@
266289
\begin{block}{After object declaration, arguments within \{\}}
267290
\begin{cppcode*}{}
268291
struct A {
269-
int a;
270-
float b;
292+
int i;
293+
float f;
271294
A();
272295
A(int);
273296
A(int, int);
@@ -287,8 +310,8 @@
287310
\begin{block}{Arguments are given within (), aka \cpp98 nightmare}
288311
\begin{cppcode*}{}
289312
struct A {
290-
int a;
291-
float b;
313+
int i;
314+
float f;
292315
A();
293316
A(int);
294317
A(int, int);

‎talk/objectorientation/operators.tex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
float m_real, m_imaginary;
88
Complex(float real, float imaginary);
99
Complex operator+(const Complex& other) {
10-
return Complex(m_real + other.m_real,
11-
m_imaginary + other.m_imaginary);
10+
return Complex{m_real + other.m_real,
11+
m_imaginary + other.m_imaginary};
1212
}
1313
};
1414

@@ -57,7 +57,7 @@
5757
struct Complex {
5858
float m_real, m_imaginary;
5959
Complex operator+(float other) {
60-
return Complex(m_real + other, m_imaginary);
60+
return Complex{m_real + other, m_imaginary};
6161
}
6262
};
6363
Complex c1{2.f, 3.f};
@@ -67,7 +67,7 @@
6767
\pause
6868
\begin{cppcode*}{firstnumber=10}
6969
Complex operator+(float a, const Complex& obj) {
70-
return Complex(a + obj.m_real, obj.m_imaginary);
70+
return Complex{a + obj.m_real, obj.m_imaginary};
7171
}
7272
\end{cppcode*}
7373
\end{block}
@@ -102,7 +102,7 @@
102102
\item They gain access to all private/protected members
103103
\item Useful for operators such as \cppinline{a + b}
104104
\item Don't abuse friends to go around a wrongly designed interface
105-
\item Avoid unexpected modifications of class state in a friend
105+
\item Avoid unexpected modifications of class state in a friend!
106106
\end{itemize}
107107
\end{block}
108108
\begin{exampleblock}{\texttt{operator+} as a friend}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /