So I am a fairly experienced C programmer who has to program in C++ a lot. There are some subtleties about the language that I have never felt to confident on. For example, the best methods of passing arguments.
Suppose for example, that I have a black-box class called Object (it might have a lot of member variables for all we know), and a function fn that takes a vector of Object instances as its argument. It seems to me that there are four basic ways of passing this:
void fn(vector<Object> vec);
void fn(vector<Object*> vec);
void fn(vector<Object> *vec);
void fn(vector<Object> &vec);
And of course, we could also take some combination of these features.
I want to make sure I have this straight:
Method 1 would copy the vector class including a copy of each Object instance in the vector. This could potentially be a huge overload and thus is bad.
(this one I'm not so sure on) Method 2 would copy all of the method variables of vec, but it would only copy the addresses of each of the Object instances. I don't know enough about what's contained in the vector class to know whether this is advisable or not.
Method 3 & 4 are fairly straightforward and similar to one another and introduce minimal overhead.
Is all this correct? and which is the preferred method keeping in mind we know nothing about the Object class?