How to pass a vector as a parameter of a function in C++

For a unidimensional vector, you declare your function like this:

void foo( vector<int> & bar )
//do something

And this way for a bidimensional vector:

void foo( vector<vector<int> > & bar )
//do something

To pass a vector pointer to a function, you must use the & symbol.

Remember to leave the space between the two “> >”.

This is how you use the function:

vector<int> bar;


More about their usage:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: