[Solved] Expected primarly expression before ]? (C++)


The error message tells you that an expression is expected at a certain point in your code:

calcNumbers(myArr[missing expression here ], type);

Why is that? Because operator[] takes an argument (traditionally an index), as in myArr[1]. No argument, no compile.

Note that this error occurs when you are using myArr. You have other places where [] is used in a declaration, and in those locations it is accepted as it is part of the type. If you have an array and you want to pass the entire array as a parameter, use just the variable name, as in calcNumbers(myArr, type);. (This would assume that myArr is an array, even though it is not in your code. You declare myArr as type int.)

Then again, your code has many problems with array usage (such as the lack of a bound on the index in askNumbers). You may want to find a good tutorial on array usage in C++. Or see if you can use std::vector after reading vector – C++ Reference or std::vector – cppreference.com.

1

solved Expected primarly expression before ]? (C++)