Thiago R. Adams website

Home Blog Code-Blog Twitter Downloads Links / Books About

Websites

VC++ Warning tips

How to disable warnings?


#pragma warning( push )
#pragma warning( disable : 4705 )
#pragma warning( disable : 4706 )
#pragma warning( disable : 4707 )
// Some code
#pragma warning( pop ) 

Useful warnings that are off by default can be enabled

My favorites are:

//class' : class has virtual functions, but destructor is not virtual
// C4265.cpp
// compile with: /W3 /c
#pragma warning(default : 4265)
class B
{
public:
   virtual void vmf();

   ~B();
   // try the following line instead
   // virtual ~B();
};   // C4265

int main()
{
   B b;
}

Sample 2:

//enumerator 'identifier' in switch of enum 'enumeration' is not explicitly handled by a case label
// C4061.cpp
// compile with: /W4
#pragma warning(default : 4061)

enum E { a, b, c };
void func ( E e )
{
   switch(e)
   {
      case a:
      case b:
      default:
         break;
   }   // C4061 c' not handled
}

int main()
{
}

See the complete list at: Compiler Warnings That Are Off by Default

Want to see more? Go to the CodeBlog section.

About the author: I am Thiago Adams. I work as a professional C++ software engineer. I have created this website to share ideas and source code with other people with similar interests.
I would like to hear from you comments, critics, questions and suggestions about this topic or any other part of this website. Email: thiago.adams at gmail dot com