禁用单个警告错误

有没有一种方法可以通过Visual Studio禁用cpp文件中的单个警告行?

例如,如果我捕获一个异常但不处理它,则会收到错误4101(未引用的局部变量)。有没有一种方法可以仅在该函数中忽略它,否则可以在编译单元中报告它?此刻,我将#pragma warning (disable : 4101)文件放在顶部,但是很明显,整个文件都将其关闭。


尚方宝剑之说
浏览 412回答 3
3回答

拉丁的传说

#pragma warning( push )#pragma warning( disable : 4101)// Your function#pragma warning( pop ) 

萧十郎

如果只想在一行代码中禁止显示警告,则可以使用suppress 警告说明符:#pragma warning(suppress: 4101)// here goes your single line of code where the warning occurs对于单行代码,其工作原理与编写以下代码相同:#pragma warning(push)#pragma warning(disable: 4101)// here goes your code where the warning occurs#pragma warning(pop)

HUWWW

#pragma push / pop通常是解决此类问题的方法,但是在这种情况下,为什么不删除未引用的变量呢?try{    // ...}catch(const your_exception_type &) // type specified but no variable declared{    // ...}
打开App,查看更多内容
随时随地看视频慕课网APP