Note: You must be registered in order to post a reply. To register, click here. Registration is FREE!
T O P I C R E V I E W
Nai
Posted - 05/30/2005 : 12:23:22 PM Origin Version (Select Help-->About Origin): Originro 7.5 SR5 Operating System: Windows 2000
For some reason I hit a general operation failure whenever I hit element v[498] WITHIN the FOR LOOP in the following subroutine: int subMaxIndex(vector<double>& v){ printf("\n v[497] = %f", v[497]); printf("\n v[498] = %f", v[498]); //it prints here printf("\n v[499] = %f", v[499]); //it prints here printf("\n v.GetSize() = %d", v.GetSize()); for(int i=0; v[i]<v[i+1] && i<499;i++){ //it does not exceed v[498 here] printf("\n v[%d] = %f", i,v[i]); } if(i==v.GetSize()) return -1; return i; }
Notice that I can access vector elements 498 and 499 outside of the FOR loop, but not inside it in the expression 2 condition. Odd? or is it just me!
1 L A T E S T R E P L I E S (Newest First)
Mike Buess
Posted - 05/30/2005 : 1:13:11 PM Try reversing the order of your conditions...
for(int i=0; i<499 && v[i]<v[i+1]; i++)
...I suspect that v[499] is the last element and the error occurs when the condition v[499]<v[500] is tested. Testing i first avoids that.