I am currently attempting to overload the ++ operator on the .begin() for my square list contatiner.
My in my hpp file I have the following:
template <typename T_>
class sq_list
{
public:
typedef T_* iterator;
iterator _itr;
square_list( iterator n ) : _itr(n) { }
sq_list operator ++ (sq_list<int> lhs) {
return lhs++;
}
};
Currently this requires me to put the iterator inside of the square list object.
What I need it to do is to call the ++ method when the .cpp file does a ++name.begin(); instead of putting that value inside of my container and then incrementing that container.
How do I get my overloaded function to work just on the ++name.begin() to increment my iterator instead of having to put it inside my sq_list container?
Thanks!
In general, you need to define the operator on the iterator. Here, your iterator is a pointer to the underlying element type, so ++ already works on that. Have you tried calling ++ simply on the iterator, without an
operator++implementation at all?