在Visual Studio中分别抑制C4189
Suppress C4189 in Visual Studio for each
我在Visual Studio 2013上工作,得到了一个简单的循环
for each (const std::string &foo in stringList)
{
/*Things happen here where foo is never used for*/
}
在循环中,我从列表中弹出N个元素,所以我不在这里使用foo,并得到C4189警告(w4),我想在这里抑制。
我环顾四周,发现了几个解决方案,如
for each (const std::string &foo in stringList)
{
(void)foo;
/*Things happen here where foo is never used for*/
}
或定义像#define UNUSED __pragma(warning(suppress:4189))
我个人喜欢define解决方案,它似乎不能在循环中工作,因为如果我使用define,我仍然会得到警告。
我的问题是:
是否有一种方法可以在不设置编译器标志的情况下抑制警告?我不希望在循环中使用额外的行来抑制警告。
c++ 17起:
for ([[maybe_unused]] const auto &foo in stringList)
{
/*Things happen here where foo is never used for*/
}
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在MS Visual Studio 2019中运行QT UI
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- Visual Studio Code - C++ Debugger 無法啟動
- Visual C++ constexpr Hints
- 为什么它不适用于Visual 2019的原因
- Visual Studio 2019:插入多个C++风格的单行注释
- Visual Studio Code "undefined reference to `WinMain@16'"
- visual在c++中将十进制数转换为二进制数
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- Visual Studio中的函数声明和函数定义问题
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual C++(VS2017)中用户定义的转换不明确
- Visual C++GC接口如何启用它以及要包含哪个库
- visual是否可以在c++中创建一个接收无限数量相同类型(或至少相当数量)参数的函数
- visual c++,如何获取解决方案目录中的代码
- Visual Studio mkl_link_tool.exe链接错误
- 在Visual Studio中分别抑制C4189