I was wondering the best approach to this design...
Say that we have two classes: X and X_iter.
Now X would be a container, and X_iter would be an iterator for that class.
Now, X would have certain functions that allows its iterators to access the data it needs. These members are naturally protected/private, since the outside has no business with these. But X_iter needs access to these functions. But making the X_iter a friend, it gets access to all internals, even the ones it should never touch.
Also, though I'd ask this, too:
Similarly, X_iter contains constructors that allows it to get access to the information it needs, and it is likely some constructors therefore are protected/private, because only the container class should be able to construct an iterator using these constructors.
What is the best approach to these? Friends? Public?
Code:class X { protected: // Some iterator methods // X_iter needs access to these public: X_iter begin() { return X_iter(some_arguments_here); } }; class X_iter { protected: X_iter(some_type_here); // The container class X needs access to this };



LinkBack URL
About LinkBacks



