File tree Expand file tree Collapse file tree 1 file changed +35
-12
lines changed
docs/error-messages/compiler-errors-2 Expand file tree Collapse file tree 1 file changed +35
-12
lines changed Original file line number Diff line number Diff line change 11---
2- description : " Learn more about: Compiler Error C2601"
32title : " Compiler Error C2601"
4- ms.date : " 11/04/2016"
3+ description : " Learn more about: Compiler Error C2601"
4+ ms.date : 06/04/2025
55f1_keywords : ["C2601"]
66helpviewer_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
1314Code 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+ ```
You can’t perform that action at this time.
0 commit comments