int InsertByValue(int array[], int & array_size, int value)
{
int desired_index;
int InsertByIndex;
desired_index = BinarySearch(array[],array_size, value, index,0, array_size - 1);
InsertByIndex(array[], array_size, desired_index, value, desired_index);
};
/*
it is saying that for desired_index; and InserByIndex;
No idea why it would be saying that. Anyone know?
*/
最佳答案
因此,当 C++ 告诉您它“需要一个表达式”时,它是说您无意中告诉它您将提供一系列运算符和操作数,或者由某些运算符(如“=”)操作的对象或数据"或 "+")。
它是构成表达式的操作数(数据或对象)和运算符(“+”、“=”或“+=”和“[]”)的组合。
现在问题的根源在这里: 当您像在 InsertByValue 函数中那样在 C++ 中声明一个函数时,您必须告诉它传递给该函数的其中一项是一个数组。这就是为什么将“[]”放在第一行的函数定义中的原因。
但是,当您稍后在函数中使用这些数组时,“[]”将作为一个运算符从该数组中获取一个对象。当有运算符时,需要有操作数,而您没有提供。
简而言之,您不需要在调用 InsertByIndex 和 BinarySearch 时使用“[]”。
关于c++ - 错误消息 "expected expression"....有人知道为什么这么说吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52508466/