From e1b8b4c9f2d9635e6028a0517f4a85f08c7bfe7e Mon Sep 17 00:00:00 2001 From: vladon Date: Mon, 17 Aug 2015 20:06:58 +0300 Subject: [PATCH] best idea is to use brace initialization --- 03-Style.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/03-Style.md b/03-Style.md index 38bb2c7..f75ca11 100644 --- a/03-Style.md +++ b/03-Style.md @@ -264,6 +264,18 @@ private: // ... // ``` inside the class body. This makes sure that no constructor ever "forgets" to initialize a member object. + +Use brace initialization, it does not allow narrowing at compile-time: +```cpp +// Best Idea + +// ... // +private: + int m_value{ 0 }; +// ... // +``` +Prefer {} initialization over alternatives unless you have a strong reason not to. + Forgetting to initialize a member is a source of undefined behavior bugs which are often extremely hard to find.