Passing arrays as a constant reference parameter?

I have an assignment which asks me to "Make sure to pass the array as a constant reference parameter"....what exactly does this mean? What's it asking me to make sure I do?
Well, an array is really just a const pointer to a the first element. Does this kind of point you in the right direction?
By reference they probably mean you should pass the array by reference (&). constant meaning it should be a reference to a const array. That is so you can't make changes to the array.
closed account (zb0S216C)
Here's the syntax:

void Function(const <TYPE-ID>(&<ID>)[<LENGTH>]));

Description:

<TYPE-ID>: Is the type which shall be referred to.
<ID>: Is the name of the reference. You'll use this to refer to the array.
<LENGTH>: The amount of elements in the array. This is required.

Wazzak
Last edited on
IMHO, prefer using a typedef; makes it a lot more readable.

1
2
3
enum { N = 100 } ;
typedef const int array_type[N] ;
void foo( const array_type& a ) ;
Last edited on
Topic archived. No new replies allowed.