In most scripting languages, objects are typically a collection of items, bound to names within those objects. For example (in Javascript), say if I were to initialize this:
colors = {
Blue: 0x0000FF; //Hex Values
Green: 0x00FF00;
Red: 0xFF0000;
}
At runtime, if a user typeed in a listed color, I can easily return the corresponding hex value using colors["given_color"].
However, how would I express an even remotely similar mechanic in C++, or other compiled languages for that matter? Creating an enum would only have meaning statically, where in a contrived example:
public enum colors{
CYAN = 0x00FFFF,
MAGENTA = 0xFF00FF,
YELLOW = 0xFFFF00
}
cannot, in any way, be used to look up the corresponding Hex of say std::cin << givenColor;
That being said, what options do I have to convert a std::string into a data point, pointer, or function pointer?
Aucun commentaire:
Enregistrer un commentaire