I am a bit new at c++, so the question may be without any meaning, so, sorry about that in advance. So, i have a class of hashtable, my hashtable is vector of vectors, it means
You need to implement your myiterator
. There are lots of way to do that, but at very least you must add something to myiterator
. For instance
class myiterator{
public:
myiterator();
myiterator(std::vector<std::vector<std::string> >& v, int ii, int jj) :
vec(v), i(ii), j(jj) {}
std::string operator*();
myiterator& operator++(); // prefix operator
myiterator operator++(int); // postfix operator
myiterator& operator--(); // prefix operator
myiterator operator--(int); // postfix operator
std::string* operator->();
private:
std::vector<std::vector<std::string> >& vec; // the vector we are iterating over
int i; // the position in the vector (first dimension)
int j; // the position in the vector (second dimension)
};
myiterator begin() {return myiterator(htable, 0, 0);}
Lots of other ways to do it, and the above may not be exactly what you want, but hopefully this gives you the idea, myiterator
must have some data members that hold the vector being iterated over and the position reached so far.
Also note the return type of operator*
is wrong, it should (presumably) be std::string
. Some of the other operators don't look right either, I've put what I think is correct in the code.