Skip to content

Update C2166 error reference #5473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions docs/error-messages/compiler-errors-1/compiler-error-c2166.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
---
description: "Learn more about: Compiler Error C2166"
title: "Compiler Error C2166"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2166"
ms.date: 06/29/2025
f1_keywords: ["C2166"]
helpviewer_keywords: ["C2166"]
ms.assetid: 12789c3a-cc76-48bb-ae2e-64283e0964ed
---
# Compiler Error C2166

l-value specifies const object
> l-value specifies const object

## Remarks

Code attempts to modify an item declared **`const`**.

The following sample generates C2166:
## Example

The following example generates C2166:

```cpp
// C2166.cpp
int f();
int main() {
( (const int&) 1 ) = 5; // C2166
int main()
{
((const int&)1) = 5; // C2166
}
```