visual-studio-2008 – 在Visual Studio 2008中禁用警告

环境:Visual Studio警告级别设置为4,

解决方案中唯一的文件中的代码:

#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仍然显示.
我尝试过的其他事情:

>将带有’// mark’的行作为应用的最后一行,没有效果.
>如果我在没有push / pop的情况下使用#pragma warning(disable:4503 4702),它可以工作,但它影响了整个解决方案之后编译的内容,即使我把#pragma warning(默认值:xx)放在某个地方,它似乎也不会将警告设置回默认状态.

谁知道为什么会这样,以及在视觉工作室中抑制警告的最佳解决方案是什么.干杯.

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

粗略地说,原因是因为我的代码中生成的警告不在头文件中,因为它是模板.代码是在头文件中生成的,方式可行.

点赞