我有这样的课程:
class ParkingLot
{
public:
int spaces;
virtual bool something() { return true; }
}
class ParkingLotBuilding
{
public:
ParkingLot Floor1, Floor2;
}
我有很多需要 ParkingLotBuilding 的功能。假设某人(我)来自 ParkingLot 和 ParkingLotBuilding:
class DerivedParkingLot : public ParkingLot
{
public:
virtual bool something() { return false; }
}
class DerivedParkingLotBuilding : public ParkingLotBuilding
{
public:
// how can I make it so that Floor1 and Floor2 are for DerivedParkingLot?
}
我有一些我无法控制的功能,如下所示:
CheckBuilding( ParkingLotBuilding &building )
{
if(building.Floor1.something() == true)
// error
}
如果我将 DerivedParkingLotBuilding 对象传递给该函数,我该如何让它调用 DerivedParkingLot::something() 返回 false?那可能吗?抱歉,如果我没有正确解释这一点,我不知道如何询问这个问题。谢谢