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 38da983

Browse files
bernhardmgrubersponce
authored andcommitted
Add a slide on the rule of zero
1 parent 4dfec0b commit 38da983

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

‎talk/morelanguage/raii.tex‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,29 @@
426426

427427
\end{advanced}
428428

429+
\begin{frame}[fragile]
430+
\frametitlecpp[11]{Rule of zero}
431+
\begin{goodpracticeWithShortcut}{Single responsibility principle (SRP)}{Single responsibility principle}
432+
Every class should have only one responsibility.
433+
\end{goodpracticeWithShortcut}
434+
\begin{goodpractice}{Rule of zero}
435+
\begin{itemize}
436+
\item If your class has any special member functions (except ctor.)
437+
\begin{itemize}
438+
\item Your class probably deals with a resource, use RAII
439+
\item Your class should only deal with this resource (SRP)
440+
\item Apply rule of 3/5: write/default/delete all special members
441+
\end{itemize}
442+
\item Otherwise: do not declare any special members (rule of zero)
443+
\begin{itemize}
444+
\item A constructor is fine, if you need some setup
445+
\item If your class holds a resource as data member:\\
446+
wrap it in a smart pointer, container, or any other RAII class
447+
\end{itemize}
448+
\end{itemize}
449+
\end{goodpractice}
450+
\end{frame}
451+
429452
\begin{frame}[fragile]
430453
\frametitlecpp[98]{smart pointers}
431454
\begin{exercise}{Smart pointers}

‎talk/objectorientation/constructors.tex‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,9 @@
101101
};
102102
\end{cppcode}
103103
\pause
104-
\begin{exampleblock}{The rule of 3/5/0 (\cpp98/\cpp11 and newer) - {\color{blue!50!white} \href{https://en.cppreference.com/w/cpp/language/rule_of_three}{cppreference}}}
105-
\begin{itemize}
106-
\item if a class has a destructor, a copy/move constructor or a copy/move assignment operator, it should have all three/five. strive for having none by using RAII types as members.
107-
\end{itemize}
108-
\end{exampleblock}
104+
\begin{goodpracticeWithShortcut}{The rule of 3/5 (\cpp98/11) - \href{https://en.cppreference.com/w/cpp/language/rule_of_three}{cppreference}}{Rule of 3/5}
105+
if a class needs a custom destructor, a copy/move constructor or a copy/move assignment operator, it should have all three/five.
106+
\end{goodpracticeWithShortcut}
109107
\end{frame}
110108

111109
\begin{frame}[fragile]

0 commit comments

Comments
(0)

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