I really appreciate your attempts at finding a new and more suitable solution but I rather have my method working.
After some research I came up with a solution: I switched from
Code:
vector<Veiculo *>::iterator it;
to
Code:
vector<Veiculo *>::const_iterator it;
It does make sense considering the vector "vehicles" is not changed at all.
Although I don't understand why'd the compiler detect an error without "const".
Here's how it looks now.
Code:
class Frota {
vector<Vehicle *> vehicles;
public:
int lowestYear() const;
};
int Frota::lowestYear() const{
int lowestYear = 2014;
vector<Vehicle *>::const_iterator it;
if (vehicles.size() != 0) {
for (it = vehicles.begin(); it != vehicles.end(); ++it)
int year = (*it)->getYear();
if (year < lowestYear) {
lowestYear = ano;
}
}
return lowestYear;
}
return 0;
}