I'm trying to define an overload for the != operator. My code is as follows. (Update: outdated code. If one of two article pointers points to NULL, this code will crash.)
bool ArticleContainer::ArticleIterator::operator!=(const ArticleIterator& artit) {
if (this->article == NULL && artit.article == NULL)
return false;
else if (this->article->GetID() != artit.article->GetID())
return true;
else if (this->article->GetName() != artit.article->GetName())
return true;
else
return false;
}
When I put a breakpoint on its first line of code, I saw this in the debugger.
this - 0x22fedc
artit - Unable to create variable object
Apparently the function can't access artit
, so it crashes. What am I doing wrong?
Edit: the call happens here.
for (ArticleContainer::ArticleIterator art = cont.Begin(); art != cont.End(); art++) {
cout << art << "\n";
}
Basically, I walk through a list of articles until I encounter the sentinel.
I just tested cont.End()
right before the for loop:
const ArticleIterator& End() const { return *tail; }
With tail:
Name : tail
Details:0x571900
Edit: operator++ code is as follows:
void ArticleContainer::ArticleIterator::operator++(int i) {
this->article = this->next->article;
this->next = this->next->next;
}