I am developing a class which acts as a container for another class. In the container class I must implement a method to get all elements in the collection. My container class uses a std::deque.
Should I return a reference to the deque?
Should I return a copy of the deque? (my god tell me this is not the answer… 🙂 )
Should I return an array?
…
What’s the best practice in this context?
Thank you
The best practice IMHO is to use the iterator design pattern and return iterators
As far as your particular example is concerned I would do something like this: