switch case with two parameters

Hi,

I know a switch case with one parameter:

1
2
3
4
5
            switch (i) {

                case (0): matrix_tmp[i][j] = 77;

            }


but, how can I pass two parameters?

I tried

1
2
3
4
5
            switch (i,j) {

                case (0,0): matrix_tmp[i][j] = 77;

            }


but case (0,0) is not allowed.


You can't. As simple as that.
The closest you can get to your example is this:
1
2
3
4
5
6
7
8
9
10
11
12
13
switch (i){
    case 0:
        {
            switch (j){
                case 0:
                    matrix_tmp[i][j] = 77;
                    break;
                //...
            }
        }
        break;
    //...
}
Last edited on
or you could use std::pair<int,int> or whatever struct/class you decalre that has 2 or more data members
switch only works for integral types (char, short, long, int, etc.). It can't be used for floating point values and it can't be used for objects.
Topic archived. No new replies allowed.