This line:
myiterator& operator++(int) {myiterator tmp(*this); operator++(); return tmp;}
Must be:
myiterator operator++(int) {myiterator tmp(*this); operator++(); return tmp;}
As a note:
You really don't need a copy constructor:
myiterator(const myiterator& mit) : p(mit.p) {}
The generated version of the compiler will work fine (since the three / four rule does not apply, since you do not own the RAW pointer contained in your class).
Your comparison operators should be marked as const, and I personally prefer to define the! = Operator in terms of the == operator and let the compiler optimize any inefficiency (although this is just a personal thing).
bool operator==(const myiterator& rhs) const {return p==rhs.p;} bool operator!=(const myiterator& rhs) const {return !(*this == rhs);}
The * operator must have two versions. Normal and constant versions.
int& operator*() {return *p;} int const& operator*() const {return *p;}
As a final note: the pointer itself is an iterator. So in fact you donβt need to wrap pointers around to make them iterators, they will behave correctly as iterators (not just input iterators, but random access iterators).
source share