2

I'd like to enable the warning for "Variable name hiding" as an error in MSVC++, so that things like this will be flagged as an error:

class A
{
    int var ;
    A()
    {
      int var = 5 ; // HIDING: want this to be an error
    }
} ;
bobobobo
  • 64,917
  • 62
  • 258
  • 363
  • To even enable the 6000 series warnings, you have to [perform this procedure](http://stackoverflow.com/a/10163994/111307). – bobobobo Apr 16 '12 at 03:59

4 Answers4

4

You can use pragma directives:

#pragma warning(error: 6244)

class A
{
    int var ;
    A()
    {
      int var = 5 ; // HIDING: want this to be an error
    }
} ;
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • 3
    @AshBurlaczenko my crystal globe told me to read the title. :) – Luchian Grigore Apr 14 '12 at 19:26
  • Actually I prefer this way, but unfortunately may have the ["include order" problem](http://stackoverflow.com/questions/7082265/what-is-the-first-line-of-code-that-will-be-compiled). Hence my selection of [the project setting answer](http://stackoverflow.com/a/10157047/111307) as the accepted one – bobobobo Apr 14 '12 at 20:41
1

for Visual Studio 2010 goto "Project Properties -> C/C++ -> Advanced"

enter image description here

pag3faul7
  • 428
  • 2
  • 7
  • So, this doesn't actually work. I still don't know how to [enable](http://stackoverflow.com/questions/4151908/enable-a-single-warning-in-visual-studio) 6000* series warnings – bobobobo Apr 15 '12 at 16:35
  • 1
    Ok, now I know [how to enable the 6000 series warnings](http://stackoverflow.com/a/10163994/111307). – bobobobo Apr 16 '12 at 03:58
0

there is a treat specific warning as error on the advanced tab of the C++ property pages of your project setting

engf-010
  • 3,980
  • 1
  • 14
  • 25
0

You can use the /we compiler option to turn a particular error into a warning. For example, /we6244 will make warning C6244 an error. See the documentation for the /w option and its friends for details.

James McNellis
  • 348,265
  • 75
  • 913
  • 977