Quote:
I think returning a const reference or a copy of the local vector is good for get, and then you can keep your add function. If the vector is empty the user of the class can just check the returned vector, and if they want to iterate through it they can do that themselves. However, you would still be encapsulating the modification of the vector.
hmm... that brings to mind something: returning a const reference or a copy of the local vector fixes the underlying implementation to a vector (unless one wants to waste time with some kind of translation to a vector). In view of an assumption that "the other code needs to iterate through the list of nicknames", it may be better in such a case to return an iterator instead, e.g.,