I am implementing a custom iterator for a library, and am overloading the operators ++ and --. My prefix operators for these work perfectly, but my post operators cause memory leaks.
avl_iterator& operator++()
{
_node = utilities::next_node( _node );
return (*this);
}
avl_iterator& operator ++( int ) {
avl_iterator temp(*this);
++(*this);
return(temp);
}
avl_iterator& operator -- () {
_node = utilities::prev_node( _node );
return (*this);
}
avl_iterator& operator -- ( int ) {
avl_iterator temp(*this);
--(*this);
return(temp);
}
I realize that this is because I am returning a temporary variable, but I can't seem to think (or find) a better way of doing this.