I've created a custom test iterator structure that iterates through a pre-defined array for testing purposes. However, as with all projects, somethings never go right the first time. So, the iterator structure is very simple, and yet a simple problem eludes me. Here's the structure first of all:
int *Array( newint[ 3 ] );
struct Itor
{
Itor( void )
{
Current = 0;
EndIndex = 2;
}
int Current, EndIndex;
int &GoForward( void )
{
if( ( Current + 1 ) > EndIndex )
return Array[ ( Current = 0 ) ];
elsereturn Array[ ( Current++ ) ];
}
int &GoBack( void )
{
if( ( Current - 1 ) < 0 )
return Array[ ( Current = 0 ) ];
elsereturn Array[ ( Current-- ) ];
}
};
In main( ), I call GoForward( ) 3 times. However, the first two calls print the first two values of Array as expected. Here's the problem: the third call supposed to print the third( final ) value in Array but it prints the first instead.
Right now I'm worn out, and I just want to find this problem before I fall asleep on the keyboard( I don't want an error saying: Undeclared identifier: 'ccccccccccccccccccccccccccccccccccccccccccccc' ).