在 Visual Studio 2008 中禁用警告 [英] Disable warnings in Visual Studio 2008

查看:42
本文介绍了在 Visual Studio 2008 中禁用警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Env:Visual Studio 警告级别设置为 4,解决方案中唯一文件中的代码:

Env: Visual Studio Warning Level is set to 4, Code in the only file in solution:

#pragma warning( push )
#pragma warning( disable: 4503 )
#pragma warning( disable: 4702 )
#include <boost/property_tree/ptree.hpp>
#pragma warning ( pop ) //mark

#include "iostream"

int main()
{
boost::property_tree::ptree pt;
for( boost::property_tree::ptree::const_iterator it = pt.begin();
     it != pt.end();
     ++it )
    {
    std::cout << it->second.data() << '\n';
    }

return 0;
}

问题:编译时仍然出现警告 4503.我尝试过的其他东西:

Problem: Warning 4503 still show up when compiling. Something else I have tried:

  1. 将带有//mark"的行作为应用程序的最后一行,无效.
  2. 如果我使用 #pragma warning( disable: 4503 4702 ) 而没有推送/弹出,它可以工作,但它会影响之后为整个解决方案编译的内容,即使我将 #pragma warning( default: xx ) 放在某处,它也不会't 似乎将警告设置回默认状态.

谁知道为什么会发生这种情况,以及在 Visual Studio 中抑制警告的最佳解决方案是什么.干杯.

Who knows why this is happening and what's the best solution for suppressing warnings in visual studio. cheers.

推荐答案

从这里找到答案:http://connect.microsoft.com/VisualStudio/feedback/details/442051/cannot-suppress-warning-in-template-功能

found answer from here:http://connect.microsoft.com/VisualStudio/feedback/details/442051/cannot-suppress-warning-in-template-function

粗略地说,原因是因为我的代码中生成的警告不在头文件中,因为它是模板.如果代码是在头文件中生成的,这样就行了.

Roughly, the reason is because the warnings generated in my code while not in header file, because it's template. It the code is generated in header files, the way would work.

这篇关于在 Visual Studio 2008 中禁用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆