switch case with two parameters

Apr 27, 2009 at 2:11pm
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.


Apr 27, 2009 at 3:20pm
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 Apr 27, 2009 at 3:20pm
Apr 28, 2009 at 6:49pm
or you could use std::pair<int,int> or whatever struct/class you decalre that has 2 or more data members
Apr 28, 2009 at 6:54pm
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.