passing an array as a const argument of a method in C++

Viewed 37569

I would like to be able to pass a const array argument to a method in C++.

I know that when you pass an array to method it is the same than passing a pointer to the first item of the array so an easy way is to use the pointer.

void myMethod(int * const inTab)

But having an array is sometimes better, you can write the size of the array for instance.

5 Answers

Try std::vector

void myMethod(const std::vector<int> &inTab);
Related