Skip to content

Commit 8e213a0

Browse files
authored
Merge pull request #5386 from Rageking8/expand-c2601-error-reference
Expand C2601 error reference
2 parents 35e3cff + db2478a commit 8e213a0

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed
Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,51 @@
11
---
2-
description: "Learn more about: Compiler Error C2601"
32
title: "Compiler Error C2601"
4-
ms.date: "11/04/2016"
3+
description: "Learn more about: Compiler Error C2601"
4+
ms.date: 06/04/2025
55
f1_keywords: ["C2601"]
66
helpviewer_keywords: ["C2601"]
7-
ms.assetid: 88275582-5f37-45d7-807d-05f06ba00965
87
---
98
# Compiler Error C2601
109

11-
'function' : local function definitions are illegal
10+
> '*function*': local function definitions are illegal
11+
12+
## Remarks
1213

1314
Code tries to define a function within a function.
1415

15-
Or, there may be an extra brace in your source code before the location of the C2601 error.
16+
Or, there may be an extra/missing brace before the location of the C2601 error.
1617

17-
The following sample generates C2601:
18+
## Examples
19+
20+
### Define function within a function
21+
22+
[Lambda Expressions](../../cpp/lambda-expressions-in-cpp.md) may be used to emulate the behavior of local functions:
1823

1924
```cpp
20-
// C2601.cpp
21-
int main() {
22-
int i = 0;
25+
// C2601a.cpp
26+
int main()
27+
{
28+
int increment(int value) // C2601
29+
{
30+
return value + 1;
31+
}
32+
33+
// Try the following line instead:
34+
// auto increment = [](int value) { return value + 1; };
2335

24-
void funcname(int j) { // C2601
25-
j++;
26-
}
36+
int two = increment(1);
2737
}
2838
```
39+
40+
### Missing closing brace
41+
42+
If a preceding function is missing a closing brace, the subsequent function is taken to be a local function:
43+
44+
```cpp
45+
// C2601b.cpp
46+
void func()
47+
{
48+
// missing '}' brace here
49+
50+
int main() {} // C2601
51+
```

0 commit comments

Comments
 (0)