Disable warnings in Visual Studio 2008

余生长醉 提交于 2019-12-07 09:31:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4181175/disable-warnings-in-visual-studio-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!