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-warnings/compiler-warning-level-1-c4251.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ helpviewer_keywords: ["C4251"]
11
11
12
12
## Remarks
13
13
14
-
This warning happens if a class is marked with `__declspec(dllexport)` or `__declspec(dllimport)` and a non-static data member that is a member of the class or a member of one of its base classes, has a type that is a class type that isn't marked with `__declspec(dllexport)` or `__declspec(dllimport)`. See [Example](#example).
14
+
This warning happens if a class is marked with `__declspec(dllexport)` or `__declspec(dllimport)` and a nonstatic data member that is a member of the class or a member of one of its base classes, has a type that is a class type that isn't marked with `__declspec(dllexport)` or `__declspec(dllimport)`. See [Example](#example).
15
15
16
16
To minimize the possibility of data corruption when exporting a class declared as [`__declspec(dllexport)`](../../cpp/dllexport-dllimport.md), ensure that:
17
17
@@ -20,11 +20,15 @@ To minimize the possibility of data corruption when exporting a class declared a
20
20
- No inlined methods of your class use CRT functions or other library functions that use static data. For more information, see [Potential errors passing CRT objects across DLL boundaries](../../c-runtime-library/potential-errors-passing-crt-objects-across-dll-boundaries.md).
21
21
- No methods of your class (whether inlined or not) can use types where the instantiation in the EXE and DLL have static data differences.
22
22
23
-
You can avoid issues when exporting a class from a DLL by defining your class to have virtual functions, a virtual destructor, and functions to instantiate and delete objects of the type. You can then call virtual functions on the type.
23
+
You can avoid issues when exporting a class from a DLL by:
24
24
25
-
C4251 can be ignored if your class is derived from a type in the C++ Standard Library, you're compiling a debug release (**`/MTd`**), and where the compiler error message refers to `_Container_base`.
25
+
- define your class to have virtual functions
26
+
- define a virtual destructor
27
+
- define functions to instantiate and delete instances of the type
26
28
27
-
Think carefully about adding `__declspec(dllexport)` or `__declspec(dllimport)` to a class because it is almost always not the right choice and it can make maintenance more difficult because it makes changing implementation details harder.
29
+
You can ignore C4251 if your class is derived from a type in the C++ Standard Library, you're compiling a debug release (**`/MTd`**), and the compiler error message refers to `_Container_base`.
30
+
31
+
Think carefully about adding `__declspec(dllexport)` or `__declspec(dllimport)` to a class because it's almost always not the right choice and it can make maintenance more difficult because it makes changing implementation details harder.
0 commit comments