File tree Expand file tree Collapse file tree 4 files changed +35
-13
lines changed Expand file tree Collapse file tree 4 files changed +35
-13
lines changed Original file line number Diff line number Diff line change 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 }
Original file line number Diff line number Diff line change 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 thread safety issues
40+ \item and do not introduce any thread- safety issues
4141 \end {itemize }
4242 \end {itemize }
4343 \end {block }
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 thread safety issues!
80+ \item introduces race conditions and thread- safety issues!
8181 \end {itemize }
8282 \end {itemize }
8383 \end {block }
Original file line number Diff line number Diff line change 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:
124145 }
125146 Vector::~Vector() { delete[] data; }
126147 \end {cppcode }
148+
149+ \end {overprint }
127150\end {frame }
128151
129152\begin {frame }[fragile]
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);
287310 \begin {block }{Arguments are given within (), aka \cpp 98 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);
Original file line number Diff line number Diff line change 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
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};
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 }
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}
You can’t perform that action at this time.
0 commit comments