I have a question about a custom forward iterator in cpp.
I'm not understanding why I need to declare the overload function == and != friend instead in the other overload operation functions like pre-increment and dereference we can avoid the use of the keyword friend.
It is just because in the equals and not equals function am I comparing two different iterators and I need to access the private members of these objects?
class _iterator {
private:
...
public:
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = T;
using pointer = value_type*;
using reference = value_type&;
_iterator(...) : ... { }
reference operator* () const {
...
}
_iterator& operator++ () {
...
}
_iterator& operator++ (int) {
...
}
friend bool operator== (const _iterator& a, const _iterator& b) {
...
}
friend bool operator!= (const _iterator& a, const _iterator& b) {
...
}
};