On Apr 23, 12:19 am, siliconmu...@[EMAIL PROTECTED]
wrote:
> Hi, I was wondering what is the point of the language sup****ting
> nested variable declarations of the same name?
> ...
> int a = 0;
> if( some_bool ) {
> int a = 5;
> ...
> }
>
> cout << a; //this outputs 0
>
> I can't think of a reason why this would be sup****ted, and I feel the
> compiler should throw a warning. So, is there a good useful reason to
> allow this?
What would the point of a "scope" be if you could not do this? Why
shouldn't this be allowed?
That said, some compilers can emit diagnostics when they detect "hiding"
or "shadowing" another name. I have to admit to having found it more
annoying than useful, but that is probably personal taste.
Chris
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|