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:
#include <iostream>
#include <vector>
usingnamespace 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!