0
0

I have some code witch plays some sounds in a switch function but I need to find some way to get rid of the sounds and the variables holding the sounds from the memory. Her is the error I get:
“Case bypasses initializations of local variable”

I have already tried with:
FSOUND_Sample_Free(click);
and
FSOUND_Close();
But non of the are working :(
and by the way I am using Borland Builder 5 if it is for some help…
Will be thankfull for some help.

  • You must to post comments
0
0

Yes it is a compiler error but it occur because of the fact that the compiler
(for some stupid reason) cant handle sound variables who are declared inside a switch.
It says it is a local variable (In the error)
The sound code are working joust fine in the rest of the program,
but not in my stupid switch. :(

  • You must to post comments
0
0

How about posting the entire compiler error so we can have a look at it and tell you what’s wrong ?

  • You must to post comments
0
0

Here is the whole error. I hope it can be to some help.

E2126 Case bypasses initialization of a local variable Compiler error

In C++ it is illegal to bypass the initialization of a local variable.

This error indicates a case label that can transfer control past this local variable.

  • You must to post comments
0
0

I see…

I guess you did something like:

[code:t0seaz1k]
switch(testvar)
{
case 1:
int j = 10;
// something
break;
case 2:
// something
break;
}
[/code:t0seaz1k]

now the line with int j = 10 throws the error you described. It means that another case statement is bypassing the initialization of j, which is not allowed in c++.
modify the code like this:

[code:t0seaz1k]
int j;
switch(somevar)
{
case 1:
j = 10;
break;
case 2:
break;
}
[/code:t0seaz1k]

  • You must to post comments
0
0

[type] variable; variable = [value];

That would work too, and would keep the code just as organized as it is now. You can CREATE a variable inside a switch statement; you just can’t pre-initialize it.

  • You must to post comments
0
0

Thanks for all the great help :)

  • You must to post comments
Showing 6 results
Your Answer

Please first to submit.