I'm implementing a bi-directional iterator for a class (a simple list that holds strings) ... the book I'm using asked me to do so ... (I'll have to implement a version of the standard list class afterwards) ... but my iterators just won't work...
here's what I have
my iterator as defined inside my list class
class iterator : std::iterator<std::bidirectional_iterator_tag, std::string>{
public:
explicit iterator(std::string* p) : element(p){};
iterator() : element(0) {};
iterator& operator++(){++element; return *this;};
iterator& operator--(){--element; return *this;};
std::string& operator*(){return *element;};
void operator=(std::string* pointer){element = pointer;};
bool operator==(iterator& it){return *this == it;};
bool operator!=(iterator& it){return *this != it;};
bool operator==(std::string* it){return element == it;};
bool operator!=(std::string* it){return element != it;};
private:
std::string* element;
};
and one of the constructors
String_list::String_list(size_type n, std::string s){
data = alloc.allocate(n);
limit = data;
size_t x = 0;
while(x != n)
++limit;
uninitialized_fill(data, limit, s);
}
if I use pointers (that are random access iterators) I can make it work just fine ... so I can only assume the problem is inside my iterator class definition ...
I get no errors at compile time ... but when run the program ... nothing happens not even the "press any key to continue..." text appears ... can anyone tell me what I'm doing wrong?