Dylan Nicholson wrote:
Is there any way of declaring the parameter "array" below to be const,
so that the function as written will not compile:
void foo(int array[] /*const*/)
{
array = array; // should not be allowed to point this at another
array!
}
As long as you are using this syntax, it can't be done in C++.
Note, that what you declare in this case is not an array but a mere
pointer. Which means that you can switch to the alternative (and
absolutely equivalent) way to declare the same parameter
void foo(int* array);
and then add const qualifications as you please
void foo(const int* array);
void foo(int* const array); // <- this is the one you need
void foo(const int* const array);
As a side note, in the C99 C language you can archive what you need with
your original syntax
void foo(int array[const]);
but this is ill-formed in C++.
--
Best regards,
Andrey Tarasevich