jump to case label [-fpermissive] code example

Example 1: error jump to case label

switch (choice)
{
    case 1: get_two_numbers(x, y);
            //* vv here vv *
            int sum = add(x, y);
            //* ^^ here ^^ */
            cout << x << " + " << y << " = " <<  sum << endl;
            break;
    case 2: get_two_numbers(x, y);
            //* vv here vv */
            int diff = subtract(x, y);
            //* ^^ here ^^ */
            cout << x << " - " << y << " = " <<  diff << endl;
            break;
    default:;
}

Example 2: error jump to case label

switch (choice)
{
    case 1:
        {
            get_two_numbers(x, y);
            int sum = add(x, y);
            cout << x << " + " << y << " = " <<  sum << endl;
        }
        break;
    case 2:
        {
            get_two_numbers(x, y);
            int diff = subtract(x, y);
            cout << x << " - " << y << " = " <<  diff << endl;
        }
        break;
    default:
        break;
}

Tags:

Cpp Example