You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: CppCoreCheck rule that enforces C++ Core Guidelines Type.6
8
8
---
9
-
# C26495 MEMBER_UNINIT
9
+
# Warning C26495
10
10
11
-
> Variable '*identifier*' is uninitialized. Always initialize a member variable (type.6).
11
+
> Variable '\**parameter-name*' is uninitialized. Always initialize a member variable (type.6).
12
12
13
13
## Remarks
14
14
15
15
A member variable isn't initialized by a constructor or by an initializer. Make sure all variables are initialized by the end of construction. For more information, see C++ Core Guidelines [Type.6](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#SS-type) and [C.48](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c48-prefer-in-class-initializers-to-member-initializers-in-constructors-for-constant-initializers).
16
16
17
+
Code analysis name: MEMBER_UNINIT
18
+
17
19
## Example
18
20
21
+
The following sample generates warning C26495 because the member variable `value` isn't initialized when a `MyStruct` object is created.
22
+
19
23
```cpp
20
24
structMyStruct
21
25
{
@@ -24,12 +28,12 @@ struct MyStruct
24
28
};
25
29
```
26
30
27
-
To fix the warning, add in-class initialization to all of the member variables:
31
+
To resolve the issue, you can add in-class initialization to all of the member variables.
28
32
29
33
```cpp
30
34
structMyStruct
31
35
{
32
-
int value{};
36
+
int value{}; // empty brace initializer sets value to 0
33
37
MyStruct() {} // no warning, MyStruct::value is set via default member initialization
0 commit comments