参数的值不能用作常量c++
value of parameter cannot be used as a constant c++
void merge(vector<Flight>& data, int low, int high, int mid, string criteria)
{
int i, j, k, temp[high - low + 1];
...
出现的错误是"the value of parameter "high"(在第 100 行声明)不能用作常量"。我没能在网上找到这个问题的合适答案。
high - low + 1
需要是 C++ 中的 编译时可计算常量表达式 。 (C++ 不支持变长数组。)
事实并非如此,因此编译器会发出诊断。
简单的解决方案是使用 std::vector<int>
作为 temp
的类型。
void merge(vector<Flight>& data, int low, int high, int mid, string criteria)
{
int i, j, k, temp[high - low + 1];
...
出现的错误是"the value of parameter "high"(在第 100 行声明)不能用作常量"。我没能在网上找到这个问题的合适答案。
high - low + 1
需要是 C++ 中的 编译时可计算常量表达式 。 (C++ 不支持变长数组。)
事实并非如此,因此编译器会发出诊断。
简单的解决方案是使用 std::vector<int>
作为 temp
的类型。