首先欢迎并感谢您的帮助。我知道当你用 C++ 创建一个数组时,索引必须是一个常量值,但我仍然得到同样的错误,让我复制并粘贴代码,以便你理解我在说什么:
const int four = 4, five=5 , six = 6, seven = 7, eight = 8, nine = 9, ten = 10, eleven = 11, twelve = 12, thirteen = 13, fourteen = 14;
这是我的常数,对吧?,现在看看这个:
switch(random_number)
{
case 4: GenerarMatrix(four,four); break;
case 5: GenerarMatrix(five,five); break;
case 6: GenerarMatrix(six,six); break;
case 7: GenerarMatrix(seven,seven); break;
case 8: GenerarMatrix(eight,eight); break;
case 9: GenerarMatrix(nine,nine); break;
case 10: GenerarMatrix(ten,ten); break;
case 11: GenerarMatrix(eleven,eleven); break;
case 12: GenerarMatrix(twelve,twelve); break;
case 13: GenerarMatrix(thirteen,thirteen); break;
case 14: GenerarMatrix(fourteen,fourteen); break;
}
我正在调用以下函数:
void GenerarMatrix( const int x, const int y)
{
int Matrix[x][y]; // Here I get an error, WHY if x and y are constant variables.
}
错误是表达式必须是一个常量值