禁用 Visual Studio 2008 中的警告

发布于 2024-10-02 06:27:39 字数 786 浏览 1 评论 0原文

Env: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。 我尝试过的其他方法:

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

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

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;
}

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

  1. put the line with '//mark' as last line of the app, no effect.
  2. if I use #pragma warning( disable: 4503 4702 ) without push/pop, it works, but it affects what's been compiled afterwards for whole solution, even I put #pragma warning( default: xx ) somewhere, it doesn't seem to set the warning back to default status.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪化雨蝶 2024-10-09 06:27:39

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

粗略地说,原因是因为我的代码中生成的警告而不是在头文件中,因为它是模板。如果代码是在头文件中生成的,那么它就可以工作。

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. If the code is generated in header files, it would work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文