I'm having trouble compiling this code, it returns me two errors when I run it:
vector<bool> cp( size );
// determine crossover point (randomly)
for( int i = _numberOfCrossoverPoints; i > 0; i-- )
{
while( 1 )
{
int p = rand() % size;
if( !cp[ p ] )
{
cp[ p ] = true;
break;
}
}
}
The first error is related to the definition of p, it says that divide by zero occurs.
The second error is related to the attempt to access cp with such p, it says iterator not dereferencable.
I wanted to understand why these errors are returned and how to solve them.