Returning a private vector
c++, iterator, oop, private, vector
Solution
Return by `const vector<char*>&`. It makes sure it won't be modified outside and it doesn't make a copy.
Problem
I have a class with a private attribute that is a vector. What is the best way of doing a getter function? - Return the whole vector: `vector<char*> getNames() { return names; }` - Would this return a copy or a pointer? Would this be accessible since its private? - Return the iterator: `vector<char*>::iterator getNames() { return names.begin(); }` - Make the vector public - I know this is bad practice for OOP, just listing options.