#include <iostream>
#include <utility>
template <typename Object>
class Vector {
class const_iterator {
public:
const Object& operator * () const { return retrieve(); }
const_iterator& operator ++ () {
++current;
return *this;
}
const_iterator operator ++ (int) {
auto old { *this};
++( *this);
return old;
}
bool operator == (const const_iterator& rhs) const { return current == rhs.current; }
bool operator != (const const_iterator& rhs) const { return !( *this == rhs); }
protected:
Object* current;
const Vector<Object>* theVect;
Object& retrieve() const {
assertIsValid();
return *current;
}
const_iterator(const Vector<Object>& vect, Object* p)
: theVect { &vect}, current {p} { }
void assertIsValid() const {
if (theVect == nullptr || current == nullptr) {
// throw IteratorOutOfBoundsException();
}
}
friend class Vector<Object>;
};
class iterator : public const_iterator {
public:
const Object& operator * () const { return const_iterator::operator * (); }
Object& operator * () { return const_cast<Object& > (std::as_const( *this).operator * () ); }
iterator& operator ++ () {
Почему ток здесь не доступен без "const_iterator ::"?
Но "++ const_iterator :: current" в порядке.
Что здесь происходит?Кто-нибудь может мне помочь?Большое спасибо!!!
++current;
return *this;
}
iterator operator ++ (int) {
auto old { *this};
++ ( *this);
return old;
}
protected:
iterator(const Vector<Object>& vect, Object* p)
: const_iterator(vect, p) { }
friend class Vector<Object>;
};
};