Reputation: 1
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?
*/
Upvotes: 0
Views: 4958
Reputation: 1098
First issue is what others have mentioned, i.e., that you don't need the []
after array in the function calls within the function body.
You are getting this error for int InsertByIndex;
because InsertByIndex
is a function name. And a function name can't be declared again to be the name of an int
variable. Since it is a function, the compiler thinks you are calling it, and is expecting (..args...)
after the identifier. When it doesn't find it, it raises an error.
Upvotes: 0
Reputation: 133
So, when C++ tells you it "expected an expression" it's saying you inadvertently told it you were going to provide a series of operators and operands, or, objects or data to be operated on by some operator (like the "=" or "+").
It's that combination of operands (data or objects) and operators ("+", "=", or "+=" and "[]") that constitutes an expression.
Now to the root of the problem here: When you declare a function in C++ like you have in the InsertByValue function, you had to tell it that one of the items passed into the function was an array. That's why you put the "[]" in the function definition in the first line.
But when you use those arrays later in the function, the "[]" is acting as an operator to get an object out of that array. And when there's an operator there needs to be operands, which you didn't provide.
In short, you don't need the "[]" in your calls to InsertByIndex and BinarySearch.
Upvotes: 1