-
Confusing Errors
Hi I keep getting these errors (using g++ on UNIX)...
vehicle_array.cc: In member function `void
vehicle_array::remove_reg(vehicle_reg&)':
vehicle_array.cc:72: error: no match for `vehicle_reg& == vehicle_reg&'
operator
vehicle_array.cc:79: error: name lookup of `i' changed for new ISO `for'
scoping
vehicle_array.cc:71: error: using obsolete binding at `i'
Here's the snipet of code it is referring to:
Code:
void vehicle_array::remove_reg(vehicle_reg& tmp){
bool ctrl = false;
for(int i = 0; i < used; i++){ //line 71
if(veh_arr[i] == tmp){ //line 72
ctrl = true;
break;
}
}
if(ctrl){
for(i ; i < used; i++){ //line 79
veh_arr[i] = veh_arr[i + 1];
}
used--;
}
}
Our instructor told us that the == operator was already overloaded for classes. Is this true? It seems to not be working in this case. I also understand this code is sorta messy, sorry. Any help would be appreciated though.
-
operator== (equality comparison) is not automatically overloaded for classes. Perhaps your teacher said that operator= (assignment) was automatically overloaded for classes? You will have to write operator== yourself.
-
As for the other error,
Code:
for(int i=0; i<5; ++i)
do_something();
cout << i; /* illegal. the variable i went out of scope at the end of the for loop */
If you want to use i after that for loop, then declare it outside of the for loop.