Charles' answer is the way to go. The reason you're getting the error message is that when you write:
if (static_cast<const Vehicle>(*this) == static_cast<const Vehicle>(car))
you're copying the vehicly bits of a couple of cars into two temporary objects. If you'd compared them by reference this wouldn't have happened:
if( static_cast<const Vehicle&>(*this) == static_cast<const Vehicle&>(car))
Having said that use the syntax Charles' outlined, it's a lot more direct and concise.
Another quick stylistic point is that you're doing a lot of ifs and elses in the derived class comparison. If you remember that an expresion like:
inGear == car.inGear
has a type of bool and a value of
true
or
false
you can rewrite the entire lot in one line:
bool Car::operator==( const Car &car ) const
{
return Vehicle::operator==( car ) && inGear == car.inGear;
}
Cheers,
Ash