Lets say I have class that use another class as feature.
class city{
void travel(){
// if rail road travel by rail
// if no rail road travel by foot
}
private:
RailRoad rails;
};
When I instantiate city
case 1 : I can have city with railroad.
case 2: I could also have city without railroad.
I thought was use RailRoad * rails and use nullptr as flag to determine the case. I was trying to avoid this because for this I have to do new and delete.
Is there any elegant way to achieve this?
Aucun commentaire:
Enregistrer un commentaire