Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
switch(1){ case 1: double d = 1; //ошибка }
Why can't you initialize in a case?
It is possible to transfer into a block, but not in a way that bypasses declarations
with initialization. A program that jumps from a point where a local variable with
automatic storage duration is not in scope to a point where it is in scope is ill-formed
unless the variable has POD type (3.9) and is declared without an initializer.
This is from the crooked heritage of C most likely.
switch/case is akin to goto but not really
, so you can do all sorts of wild things with loops and ifs that overlap parts of the switch.
And in the end, what happens.
This code is quite valid:
int x = 1;
switch (x) {
case 1:;
case 2:
int b = 2;
}
/// Даже с добавлением таких извращений
switch (x) {
case 1:
if (a == 1) {
case 2:
int b = 2;
}
}
int x = 1;
switch (x) {
case 2:
int b = 2;
case 1:;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question