You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/error-messages/compiler-errors-2/compiler-error-c2603.md
+16-9Lines changed: 16 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -34,19 +34,26 @@ translation.priority.ht:
34
34
- "zh-cn"
35
35
- "zh-tw"
36
36
---
37
-
# Compiler Error C2603
38
-
'function' : Too many block scope static objects with constructor/destructors in function
37
+
# Compiler Error C2603
39
38
40
-
There is a limit of 31 on the number of static objects you can have in an externally visible inline function.
39
+
> '*function*' : Too many block scope static objects with constructor/destructors in function
41
40
42
-
The following code generates C2603:
41
+
In versions of the Visual C++ compiler before Visual Studio 2015, or when the [/Zc:threadSafeInit-](../../build/reference/zc-threadsafeinit-thread-safe-local-static-initialization.md) compiler option is specified, there is a limit of 31 on the number of static objects you can have in an externally visible inline function.
43
42
44
-
```
43
+
To resolve this issue, we recommend you adopt more recent version of the Visual C++ compiler toolset, or if possible, remove the /Zc:threadSafeInit- compiler option. If this is not possible, consider combining your static objects. If the objects are of the same type, consider use of a single static array of that type, and reference individual members as required.
44
+
45
+
## Example
46
+
47
+
The following code generates C2603 and shows one way to fix it:
48
+
49
+
```cpp
45
50
// C2603.cpp
51
+
// Compile by using: cl /W4 /c /Zc:threadSafeInit- C2603.cpp
46
52
structC { C() {} };
47
53
extern inline void f1() {
48
-
static C C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C14,C15,C16;
49
-
static C C17,C18,C19,C20,C21,C22,C23,C24,C25,C26,C27,C28,C29,C30,C31,C32;
50
-
static C C33; // C2603 Comment this line out to avoid error
0 commit comments