Skip to content

Commit 0a15944

Browse files
Added C++11 guideline for member initialization.
1 parent 2a7773f commit 0a15944

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

03-Style.md

+10
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ private:
223223
};
224224
```
225225
226+
In C++11 you may consider to always give each member a default value, e.g. by writing
227+
```cpp
228+
// ... //
229+
private:
230+
int m_value = 0;
231+
// ... //
232+
```
233+
inside the class body. This makes sure that no constructor ever "forgets" to initialize a member object.
234+
Forgetting to initialize a member is a source of undefined behaviour bugs which are often extremely hard to find.
235+
226236

227237
## Always Use Namespaces
228238

0 commit comments

Comments
 (0)