Thursday 22 August 2013

C++ Derived class overriding member of base class with another derived class?

C++ Derived class overriding member of base class with another derived class?

I have classes like this:
class ParkingLot
{
int spaces;
virtual bool something() { return true; }
}
class ParkingLotBuilding
{
ParkingLot Floor1, Floor2;
}
I've got a whole lot of functions that take ParkingLotBuilding. Let's say
someone (me) derives from ParkingLot and ParkingLotBuilding:
class DerivedParkingLot : public ParkingLot
{
virtual bool something() { return false; }
}
class DerivedParkingLotBuilding : public ParkingLotBuilding
{
// how can I make it so that Floor1 and Floor2 are for DerivedParkingLot?
}
I've got functions I don't control that are like this:
CheckBuilding( ParkingLotBuilding &building )
{
if(building.Floor1.something() == true)
// error
}
If I pass a DerivedParkingLotBuilding object to that function how do I
make it so that it calls DerivedParkingLot::something() to return false?
Is that possible? Sorry if I didn't explain this right I'm not sure how to
ask about the problem. Thanks

No comments:

Post a Comment