How can I map elements of one enum to another?
I'm using C. I have to large enums, one of menu ID's and one of window ID's. At the moment they're mapped to each other by an array, so the elements have to be put into the array perfectly and as soon as something changes work has to be done to put them all back开发者_如何学C into the right place. What would be a better way of mapping the menus to the windows? Thanks
Are you explicitly assigning values to the members of each enum
? How do menu IDs map to window IDs? Can you post part of the enums as an example?
If the enums
are lengthy, this might be a good candidate for a code-generating script. Store your IDs in (for example) a CSV file that lists matching pairs of Window IDs and Menu IDs. Then, write a script that parses the CSV file and generates a header containing the appropriate enum
definitions. If you are building your project using makefiles (or similar), it should be fairly straightforward to integrate this type of auto-generated header into your build system.
精彩评论