Arguments are passed by value by default which means that the function receives a copy of the argument that you passed to the function. Making changes to the copy will not have any effect on the original object.
If you want the function to be able to manipulate the passed vector you can change the function so that the vector is passed by reference, like this:
Passing large objects like std::vector by reference is usually a good idea even if you don't want to manipulate the vector because it avoids copying the vector so it is more efficient. To avoid that the vector is accidentally modified inside the function you can pass it as a const reference.
1 2 3 4 5 6 7 8 9 10 11
void print(const vector<vector<int> >& maze)
{
for (size_t y = 0; y < maze.size(); ++y)
{
for (size_t x = 0; x < maze[y].size(); ++x)
{
std::cout << maze[y][x] << ' ';
}
std::cout << std::endl;
}
}
void foo (int x) { x = 7; }
void bar()
{
int y = 42;
foo( y );
cout << y;
}
// Lets "pseudo-inline" the code of foo into bar.
// This is equivalent to the one above:
void bar()
{
int y = 42;
int foo_x = y;
foo_x = 7;
cout << y;
}
Pass a reference to the vector.
1 2 3 4 5 6 7 8
void foo (int & x) { x = 7; }
// Pseudo-inline with the new foo:
void bar()
{
int y = 42;
y = 7;
cout << y;
}