Skip to content

Commit 1af81e2

Browse files
authored
Merge pull request #5500 from MicrosoftDocs/FromPublicMasterBranch
Confirm merge from FromPublicMasterBranch to main to sync with https://github.com/MicrosoftDocs/cpp-docs (branch main)
2 parents 318a421 + 8202709 commit 1af81e2

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

docs/cpp/mutable-data-members-cpp.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
---
22
description: "Learn more about: Mutable Data Members (C++)"
33
title: "Mutable Data Members (C++)"
4-
ms.date: "11/04/2016"
4+
ms.date: "03/14/2024"
55
f1_keywords: ["mutable_cpp"]
66
helpviewer_keywords: ["mutable keyword [C++]"]
7-
ms.assetid: ebe89746-3d36-43a8-8d69-f426af23f551
87
---
98
# Mutable Data Members (C++)
109

11-
This keyword can only be applied to non-static and non-const data members of a class. If a data member is declared **`mutable`**, then it is legal to assign a value to this data member from a **`const`** member function.
10+
This keyword can only be applied to non-static, non-const, and non-reference data members of a class. If a data member is declared **`mutable`**, then it is legal to assign a value to this data member from a **`const`** member function.
1211

1312
## Syntax
1413

@@ -25,19 +24,15 @@ For example, the following code will compile without error because `m_accessCoun
2524
class X
2625
{
2726
public:
28-
bool GetFlag() const
29-
{
30-
m_accessCount++;
31-
return m_flag;
32-
}
27+
bool GetFlag() const
28+
{
29+
m_accessCount++;
30+
return m_flag;
31+
}
3332
private:
34-
bool m_flag;
35-
mutable int m_accessCount;
33+
bool m_flag;
34+
mutable int m_accessCount;
3635
};
37-
38-
int main()
39-
{
40-
}
4136
```
4237

4338
## See also

0 commit comments

Comments
 (0)