I have an enum:
enum VehicleType {CAR, BIKE, TRUCK};
The following class uses this enum as a template parameter:
template <VehicleType V>
class ParkingSlotContainer
{
...
};
Now, I wish to define a class with a map data member that maps a VehicleType to ParkingSlotContainer<VehicleType>. In other words, I want to map CAR to ParkingSlotContainer<CAR>, BIKE to ParkingSlotContainer<BIKE>, etc.
This is my attempt:
class ParkingFloor
{
private:
int floor;
map<VehicleType, ParkingSlotContainer<VehicleType> > slots;
public:
ParkingFloor(...);
...
};
The compiler doesn't accept the above and reports that type name is not allowed. It expects ParkingSlotContainer<CAR|BIKE|TRUCK> instead of ParkingSlotContainer<VehicleType>.
What is the right way to define such a map?
ParkingSlotContainer<CAR> carslot; ParkingSlotContainer<BIKE> bikeslot; ParkingSlotContainer<TRUCK> truckslot;array[index].doSomething();because the compiler wouldn't know which classarray[index]was because all of them would be different.ParkingSlotContainer<VehicleType>is not a type, nor isParkingSlotContainer. The first is a hard error, and the second is a template.