I have looked at all the other posts with a similar topic, and none help, so please don't flag as a duplicate.
I am defining in main()
a const int SIZE = 20;
. Then, I pass this as an argument to my function, Mode:
int* Mode(int* numbers, int & mode, const int SIZE)
{
int occurences[SIZE];
// Calcualte mode
}
However, I get the error, expression must have a constant value
.
My function call (in main) looks like this:
int* occurencesPtr = Mode(numbersPtr, mode, SIZE);
With SIZE
being defined at the beginning to the literal 20
.
I understand that the error is because the function's version of SIZE
only acquires its value when the function is called (?), but I don't know how I could work around this.
I have even tried passing to the function a const int * const SIZEPtr = &SIZE
, but that didn't work either. Help?
EDIT: I am not trying to use a variable size!! Notice that I have made SIZE
a const
everywhere! I just want to use that same SIZE constant to declare my array.
EDIT: Dynamic arrays are not what I need. I just want a normal, named, array, defined with a constant size value passed to the function.