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
When member functions don’t modify the object's state, annotate them with the `const` keyword. This guidance comes from the [C++ Core Guideline Con.2](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#con2-by-default-make-member-functions-const).
12
12
@@ -33,7 +33,7 @@ double getRadius()
33
33
34
34
## How to fix the issue
35
35
36
-
The solution proposed by the linter is to mark member functions `const` when they don't modify the object's state. This let's both developers and the compiler know that the function is safe to call on a `const` object.
36
+
Mark member functions `const` when they don't modify the object's state. This lets both developers and the compiler know that the function is safe to call on a `const` object.
37
37
38
38
In the following example, `const` has been added to `getValue()` and `getRadius()`:
The editor can make this change for you. Place the cursor on the flagged symbol and choose **Show potential fixes** and then **Make member const**:
61
61
62
-
:::image type="complex" source="media/make-member-function-const.png" alt-text="Screenshot of the editor suggesting to make member const." :::
62
+
:::image type="complex" source="media/lnt-make-member-function-const.png" alt-text="Screenshot of the editor suggesting to make member const." :::
63
63
The cursor is on the line int getValue() and **Show potential fixes** appeared and was chosen. Now **Make member const** is visible and it shows the get value function with const added to it. You can now choose **Make member const** to make the change.
64
64
:::image-end:::
65
65
66
66
Make this change for all flagged member functions.
67
67
68
68
## Remarks
69
69
70
-
This check focuses on `const` usage for member functions in C++ code. The C++ Core Guidelines recommends marking member functions as `const` when they don't modify the object's state.
70
+
Introduced in Visual Studio 2022 17.8, this check focuses on `const` usage for member functions in C++ code. The C++ Core Guidelines recommends marking member functions as `const` when they don't modify the object's state.
71
71
72
72
The current implementation of this check allows you to add `const` to member functions after their declaration. It's a good practice to declare member functions as `const` from the beginning if they don't modify the object's state.
cpp_naming_style.boolean_style.required_prefix = b
24
24
```
25
25
26
-
The linter will flag the following code because it isn't prefixed with 'b' and it isn't Pascal case, as specified in the `.editorconfig` file:
26
+
The linter will flag the following code because it isn't prefixed with 'b' and because it isn't Pascal case, as specified in the `.editorconfig` file:
27
27
28
28
```cpp
29
29
voidexample()
@@ -51,7 +51,7 @@ The code editor shows bool myFlag = true. With the cursor on that line of code,
51
51
52
52
## Remarks
53
53
54
-
The`lnt-naming-convention` linter check ensures that naming conventions align with naming conventions specified in the `editorconfig` file. You can apply this check to any project that has an `editorconfig` file. You can also customize your `.editorconfig` file to suit your project's coding style.
54
+
Introduced in Visual Studio 2022 17.7, the`lnt-naming-convention` linter check ensures that naming conventions align with naming conventions specified in the `editorconfig` file. You can apply this check to any project that has an `editorconfig` file. You can also customize your `.editorconfig` file to suit your project's coding style.
0 commit comments