If there is a method, which aims to put objects with specific type into another list, how can I use a user-defined parameter in the dynamic_cast? I know, that I can not use the std::string parameter directly in dynamic_cast, but is there a better solution?
std::list<Car*> GetCarsOfType(std::string type)
{
std::list<Car*> carsOfType;
for (int i = 0; i < cars.size(); ++i)
{
if (dynamic_cast<type> cars[i]) // This is not possible, but how can I solve this in a better way?
{
carsOfType.push_back(cars[i]);
}
}
return carsOfType;
}