- When using C ++, to avoid empty Catch, we often specify the Exception ex parameter, but this parameter is often not used. The compiler will give a warning about unused variables, use # pragma warning to eliminate unnecessary warnings.
About # pragma warning
- # Pragma warning is only valid for the current file (for. h, it is also valid for cpp containing it), rather than for all files of the entire project. When the file compilation is complete, the setting will become useless.
- # Pragma warning (push) stores the current Alert settings.
- # Pragma warning (push, n) stores the current alarm settings and sets the alarm level to n. N is a natural number from 1 to 4.
- # Pragma warning (pop)
- Restores the alert settings that were previously pushed into the stack. Any alert settings made between push and pop fail.
- # Pragma warning (disable: n)
- # Pragma warning (default: n)
- Some warnings, such as C4309, take effect from top to bottom. That is, the # pragma warning in the file is traversed from top to bottom, and takes effect in sequence.
For example:
- Some warnings, such as C4189, are based on the # pragma warning setting that appears at the end of the function. The other settings for this alarm are invalid.
- Example: void func (){
- # Pragma warning (Disable: 4189) int x = 1; # pragma warning (default:
4189)
} Then c4189 will still appear, because the default command is the last of the function. In other functions in this file, if no resetting is performed, c4189 is also subject to # pragma warning (default: 4189. If you reset it, the last # pragma warning in the function prevails.
- Some warnings (which MSDN considers to be a warning greater than or equal to C4700) take effect only after the function is completed.
- Example: # pragma warning (Disable: 4700) void func ()
{
Warning LNK4006: NULL_IMPORT_DESCRIPTOR already defined
Solution: If you compile a static library, delete all the databases in 'additional Dependencies.