Skip to content

Commit fc9c42b

Browse files
TylerMSFTTylerMSFT
authored andcommitted
edits
1 parent 746fe09 commit fc9c42b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

docs/error-messages/compiler-warnings/compiler-warning-level-1-c4251.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ helpviewer_keywords: ["C4251"]
1111
1212
## Remarks
1313

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).
1515

1616
To minimize the possibility of data corruption when exporting a class declared as [`__declspec(dllexport)`](../../cpp/dllexport-dllimport.md), ensure that:
1717

@@ -20,11 +20,15 @@ To minimize the possibility of data corruption when exporting a class declared a
2020
- 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).
2121
- No methods of your class (whether inlined or not) can use types where the instantiation in the EXE and DLL have static data differences.
2222

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:
2424

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
2628

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.
2832

2933
## Example
3034

0 commit comments

Comments
 (0)