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 8ba1a0d

Browse files
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 5bf6194 commit 8ba1a0d

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)

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