假设我的班级有两个const int二维数组。我也有一种方法,该方法从用户那里获取布尔变量,并根据其值选择一个矩阵来在进一步的计算中使用它。如何引用这些矩阵之一?例如,如果用户提供'true'方法将对matrix_1进行操作,如果用户提供'false'方法将对matrix_2进行操作。这是示例代码:
class Foo {
public:
const int matrix_1[2][2] = { {1,1} ,{2,2} };
const int matrix_2[3][3] = { {1,2,3} ,{3,4,5}, {6,7,8} };
Foo() {}
void method(bool select) {
//pointer variable pt
if (select == true) {
//pt points to matrix_1
}
else {
//pt points to matrix_2
}
//some calculations
}
};