Accessing elements of const pass by reference std::list

What would be the proper way to access elements that are passed by const reference? Specifically std::list. ex. const std::list<std::string>& someStrings

I understand that it is a reference to memory and that it cannot be modified, but how would I copy values to new string variables or print out the contents of the list.


You use the list as normal. You can use iterators or range-based for loops to access the elements.
When an object is pass as const reference it means that you can use functions that are marked as const only.

E.g const_iterator begin() const

So copy things from that object is usually possible. I.e. you can copy the elements of the list without problems.
Topic archived. No new replies allowed.