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.
| 归档时间: |
|
| 查看次数: |
135 次 |
| 最近记录: |