We want a solution in C++ that must be able to do the following: Given a string of particular type, lets say 'A', we want to find all the types that derives from 'A'. Instantiate new objects out of the types that are derived from 'A'. E.g. Lets say we have a class, VehicleEntity. VehicleEntityhas child classes, PassangerCarEntity, TruckEntity, TrainEntity, BoatEntity. We are unsure what vehicle entities there may be as the a library could be added containing more VehicleEntities. E.g. an AirplaneEntity thaterives from VehicleEntity could be added after deployment. In the application, when a user wants to select a VehicleEntity, the user should be able to pick any of the entities deriving from VehicleEntity. This includes the PassangerCarEntity, TruckEntity, TrainEntity, BoatEntity and AirplaneEntity. The user selects an Entity, lets say AirplaneEntity, A new object of type AirplaneEntity must be instantiated.
The following is an concept example in C# of what we want to achieve in C++. In C# the items for the dropdown list can be retrieved as follows:
Type vehicleEntityType = typeof(VehicleEntity);
List<Type> types = new List<Type>();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
types.AddRange(assembly.GetTypes().Where(x => vehicleEntityType.IsAssignableFrom(x) && !x.IsGenericType && !x.IsAbstract));
dropDownBox.ItemList = types;
//To instantiate the object:
List<VehicleEntity> vehicleList = new List<VehicleEntity>();
Type newVehicleType = (Type)dropDownBox.SelectedItem;
object newVehicle = Activator.CreateInstance(newVehicleType ); // default constructor used, parameterless constructors for vehicles.
vehicleList.Add(newVehicle);
Standard C++ seems unable to do this as it does not store any metadata on its objects. There exist external libraries that provides reflection to C++. RTTI and boost.Mirror seems unable to do this. I am sure that we are not the only ones that had this problem and that solutions exist. What solutions exist to address our problem? External libraries or other means.