I am not a fan of C++ at all. Stupid professors with stupid operator overloading requirements...
Anyways, for some reason I can't find an example of overloading the '++' operator anywhere on the web. If anyone could perhaps post one or something. that's be awesome. Here's what I have in my main file:
'currentPtr' is a pointer to an element in a list. All user-defined, of course.
Here's the header:
ListIterator operator++();
It seemed pretty simple to me in class, but I can't seem to get it right. I keep trying convert incorrect types and whatnot. I got nothing. Lemme know if more code is necessary.
Oh, and, obviously, the code above is incorrect :)
When you try to increment your ListIterator you are probably saying something like this: my_iter++;
Right? ;-)
The problem is that in C++ there are _two_ increment operators: pre-increment and post-increment. You have overloaded the pre-increment operator. To overload the post-increment operator, you have to give a dummy int argument:
1 2 3 4 5
ListIterator ListIterator::operator++(int) {
ListIterator result = *this; // use copy ctor
currentPtr = this->next; // increment this
return result; // return the _unincremented_ obj
}
Also, watch out for "&this". It should be either "this" or "*this".
haha, my bad. I don't wanna put the whole code in here though. I don't know how to break it down, really. Oh well, guess I'll just work on it on my own.