There was an error while loading. Please reload this page.
1 parent eea3d25 commit 9efc2a7Copy full SHA for 9efc2a7
03-Style.md
@@ -277,11 +277,25 @@ private:
277
// ... //
278
```
279
280
-
281
Prefer {} initialization over alternatives unless you have a strong reason not to.
282
283
Forgetting to initialize a member is a source of undefined behavior bugs which are often extremely hard to find.
284
+If the member variable is not expected to change after the initialization, then mark it `const`.
285
+
286
+```cpp
287
+class MyClass
288
+{
289
+public:
290
+ MyClass(int t_value)
291
+ : m_value{t_value}
292
+ {
293
+ }
294
295
+private:
296
+ const int m_value{0};
297
+};
298
+```
299
300
## Always Use Namespaces
301
0 commit comments