Skip to content

Commit e1b8b4c

Browse files
author
vladon
committed
best idea is to use brace initialization
1 parent 0113f74 commit e1b8b4c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

03-Style.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,18 @@ private:
264264
// ... //
265265
```
266266
inside the class body. This makes sure that no constructor ever "forgets" to initialize a member object.
267+
268+
Use brace initialization, it does not allow narrowing at compile-time:
269+
```cpp
270+
// Best Idea
271+
272+
// ... //
273+
private:
274+
int m_value{ 0 };
275+
// ... //
276+
```
277+
Prefer {} initialization over alternatives unless you have a strong reason not to.
278+
267279
Forgetting to initialize a member is a source of undefined behavior bugs which are often extremely hard to find.
268280
269281

0 commit comments

Comments
 (0)