should you keep all the data except functions in your class in private section? for example: I have a std::list of integers which i need to access in other class. how would you iterate it and would you really want to keep it private?
Edit:
I’m looking for an individual access to each element in other class.
The real question is why you need to iterate over the list in the ‘other class’. If you need to perform a specific operation in the client class you could have other choices:
If you need to perform a well-defined operation (say, computing an average of the values in the list) then you can implement this functionality as a member function of the class that keeps the list.
If you need to perform all kinds of operations on the list then you can build a generic iterator interface, which accepts functions or functors that implement the various operations and return whatever results you need.
Neither of these options require you to expose the list itself.