Skip to content

Commit 0e6c7a8

Browse files
committed
Add "explicit" keyword for several unary constructors.
We recommend to use explicit for unary constructors, but we are not using is in the following slides. Here, it is added in several places where the addition doesn't create space issues on the slide.
1 parent 888e125 commit 0e6c7a8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

talk/objectorientation/constructors.tex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
\begin{cppcode}
227227
struct Delegate {
228228
int m_i;
229-
Delegate(int i) : m_i(i) {
229+
explicit Delegate(int i) : m_i(i) {
230230
... complex initialization ...
231231
}
232232
Delegate() : Delegate(42) {}
@@ -247,7 +247,7 @@
247247
\begin{exampleblock}{Practically}
248248
\begin{cppcode}
249249
struct Base {
250-
Base(int a); // ctor 1
250+
explicit Base(int a); // ctor 1
251251
};
252252
struct Derived : Base {
253253
using Base::Base;
@@ -270,9 +270,9 @@
270270
\begin{exampleblock}{Practically}
271271
\begin{cppcode}
272272
struct Base {
273-
int a{5}; // also possible: int a = 5;
274-
Base() = default;
275-
Base(int _a) : a(_a) {}
273+
int a{5}; // or: int a = 5;
274+
Base() = default;
275+
explicit Base(int _a) : a(_a) {}
276276
};
277277
struct Derived : Base {
278278
int b{6};

0 commit comments

Comments
 (0)