Help me with the library chrono

Hi, i am with problems in library chrono, because when put within of the fuction switch, appear a messenger of error, look of the picture. Sorry for my engilsh!!! My english is a trash!!!

link of the picture:

http://img.gforum.tv/img/f21bc4edd5afcd10631a9d624ecc9ab34496d5a2.jpg
A jump to a labelled statement (case xxx and default are labelled statements) is not permitted to bypass the initialisation of an object a variable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
int main()
{
        int i = 7 ;

        switch(i)
        {
            case 3 :
                // ...

            case 1 :
                int j = 25 ;
                ++j ;
                // ...
                break ;

            case 7 : // *** error: cannot jump from switch statement to this case label
                     // *** error: jump bypasses initialisation of 'int j'
                ;
                // ...
        }

        if( i < 10 ) goto label ; // *** cannot jump from this goto statement to its label

        int k = 6 ;
        ++k ;

    label:  ; // // *** error: jump bypasses initialisation of 'int k'
}

http://coliru.stacked-crooked.com/a/b9c18b546c90abdc

Fixed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
int main()
{
        int i = 7 ;

        switch(i)
        {
            case 3 :
                // ...

            case 1 :
            {
                int j = 25 ; // j is now at a local block scope
                ++j ;
                // ...
            } // which ends here
                break ;

            case 7 : 
                     
                ;
                // ...
        }
        
        int k = 6 ; // initialisation of k is now before the jump 
        if( i < 10 ) goto label ; 

        // int k = 6 ;
        ++k ;

    label:  ; 
}

http://coliru.stacked-crooked.com/a/c87a488177288672
Last edited on
Topic archived. No new replies allowed.