Skip to content

Commit 3b4a36b

Browse files
authored
Merge pull request MicrosoftDocs#3115 from JordanMaples/patch-26
Add example to C26496
2 parents 3a57e4f + b8d9ef4 commit 3b4a36b

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

docs/code-quality/c26496.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,26 @@ ms.date: 03/22/2018
44
ms.topic: reference
55
f1_keywords: ["C26496"]
66
helpviewer_keywords: ["C26496"]
7+
description: CppCoreCheck rule that enforces C++ Core Guidelines Con.4
78
---
89
# C26496 USE_CONST_FOR_VARIABLE
910

10-
> The variable '*variable*' is assigned only once, mark it as `const`. See [C++ Core Guidelines con.4](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#con4-use-const-to-define-objects-with-values-that-do-not-change-after-construction).
11+
> The variable '*variable*' is assigned only once, mark it as `const`.
12+
13+
## See also
14+
[C++ Core Guidelines con.4](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#con4-use-const-to-define-objects-with-values-that-do-not-change-after-construction).
15+
16+
## Example
17+
```cpp
18+
int GetTheNumber();
19+
int GiveMeTheNumber(int);
20+
21+
void function1()
22+
{
23+
int theNumber = GetTheNumber(); // C26496, 'theNumber' is never assigned to again, so it can be marked as const
24+
std::cout << theNumber << '\n';
25+
26+
GiveMeTheNumber(theNumber);
27+
// ...
28+
}
29+
```

0 commit comments

Comments
 (0)