Practical difference between REF and PTR

I am trying to understand the 'practical' difference between sending a container to a function as a reference and as a pointer.
Two versions of the same program, which sends a vector to the 'fillit' function, and sets 10 elements as objects, first sending the vector as a reference, and the second as a pointer.
Reference version:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  #include <iostream>
#include <vector>
using namespace std;

class grommet
{
public:
	int x;
	grommet(int x = 1) : x{ x } {}
};

void setem(vector<grommet>&temp)
{
	for (int n{}; n < 10; n++)
	{
		temp.push_back(grommet{ n * 20 });
	}
}

int main()
{
	vector<grommet>tools;
	setem(tools);
	return 0;
}

And the pointer version:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <vector>
using namespace std;

class grommet
{
public:
	int x;
	grommet(int x = 1) : x{ x } {}
};

void setem(vector<grommet>*temp)
{
	for (int n{}; n < 10; n++)
	{
		temp->push_back(grommet{ n * 20 });
	}
}

int main()
{
	vector<grommet>tools;
	setem(&tools);
	return 0;
}

Both do the exact same thing, yet the 'pointer' version seems to be looked down upon by some. So my question is, since there is no apparent 'end-result' difference between the two, why is the reference-method preferred?
Cheers!
One difference is that you can't do setem(nullptr); if you're taking a vector by reference. The 'pointer' version is more likely to result in error.
Topic archived. No new replies allowed.