From: rajesh
Neil Heller wrote:
> case 1 :
> int bar = 2;
> break;
> case 2 :
> int bar = 3;
the variable 'bar' when defined this way, only exists inside the
innermost braces. You are defining bar
as an automatic variable twice inside one pair of braces. Obviously,
this is an error..
For the same reasons, the next piece of code -will- work because of
different sets of braces ..
> case 2 : {
> int bar = 3;
> break;
> }
> }
>
> I was under the assumption that the braces weren't necessary in C++ as
> far as declaring variables is concerned.
For automatic variables they matter .. a lot
Rajesh
--- ifmail v.2.9
---------------
* Origin: Kalptaru Net - Rajesh's Linux Node - (6:606/30@fidonet)
|