I’ve been learning C++, coming from C#, where I’ve gotten used to using service providers: basically a Dictionary<Type, object>. Unfortunately, I can’t figure out how to do this in C++. So the questions are basically:
-
How would I make a dictionary in C++.
-
How would I use ‘Type’ with it, as far as I know there is no ‘Type’ in C++.
-
Same as above, but with ‘object’.
Thanks!
I’m assuming that you’re trying to map a type to a single object instance. You could try something along these lines:
In C++ types are not first-class objects in their own right, but at least the type-name is going to be unique, so you can key by that.
Edit: The names aren’t actually guaranteed to be unique, so hold on to the type_info pointers and use the before method to compare them.