I am writing a Set class in order to get a handle on how they really work, as well as to try to write my own Iterator. As far as I understand an Iterator is just a high level pointer that abstracts, well, iteration through a structure.
That being said I am aware that the important parts of an iterator are the ++ -- and * operations. I have successfully created and tested by in/decrement operators, but I am having a hell of a time conceptualizing what I need to return when I deference the Iterator.
Do I return the object it's pointing to?
Here is the relevant code in my set.h file:
class Set{
private:
struct Elem {
ELEMENT_TYPE info;
Elem *prev, *next;
};
Elem *_head, *_tail;
int _size;
public:
//...
class Iterator{
private:
Elem * _cur;
public:
Iterator(){}
Iterator( Elem* );
Iterator operator++( int );
Iterator operator++();
Iterator operator--( int);
Iterator operator--();
bool operator==( const Iterator& rhs );
bool operator!=( const Iterator& rhs );
Elem operator*();
};
//...
};
Like I said, I am returning the "Elem" that the Iterator is pointing to, is that correct?
Set::Elem* Set::Iterator::operator*(){
return _cur;
}