In C++, things are passed by value unless you specify otherwise using the &-operator (note that this operator is also used as the ‘address-of’ operator, but in a different context). This is all well documented, but I’ll re-iterate anyway:
void foo(vector
void foo(vector
void foo(vector
You can also choose to pass a pointer to a vector (void foo(vector
Also, vectors are not the same as arrays! Internally, the vector keeps track of an array of which it handles the memory management for you, but so do many other STL containers. You can’t pass a vector to a function expecting a pointer or array or vice versa (you can get access to (pointer to) the underlying array and use this though). Vectors are classes offering a lot of functionality through its member-functions, whereas pointers and arrays are built-in types. Also, vectors are dynamically allocated (which means that the size may be determined and changed at runtime) whereas the C-style arrays are statically allocated (its size is constant and must be known at compile-time), limiting their use.
I suggest you read some more about C++ in general (specifically array decay), and then have a look at the following program which illustrates the difference between arrays and pointers:
void foo1(int *arr) { cout << sizeof(arr) << 'n'; }
void foo2(int arr[]) { cout << sizeof(arr) << 'n'; }
void foo3(int arr[10]) { cout << sizeof(arr) << 'n'; }
void foo4(int (&arr)[10]) { cout << sizeof(arr) << 'n'; }
int main()
{
int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
foo1(arr);
foo2(arr);
foo3(arr);
foo4(arr);
}
A vector is functionally same as an array. But, to the language vector is a type, and int is also a type. To a function argument, an array of any type (including vector[]) is treated as pointer. A vector
So, you must use vector