c++ - Class members of different types, one for each enum variand -
i have enum this:
enum field { foo, bar, baz, // 50 more follow }
i want associate data type each value (foo - uint, bar - string, etc.), , want create class field each enum value, of type associated enum. i'd want have generic getter/setter allow atomically operate on group of fields.
is there way of that, in generic fashion - avoiding specialized methods each field, retaining type safety want? if so, how it?
honestly, if you're going this, you're going want in 2 ways:
1) create new class.
if you're sharing 50 or fields between common classes, might create common class or struct hold data.
2) use std::map<variant/enum, value>
.
to me, if want create flexible system @ cost of performance, instead implement key/value system using std::map/std::unordered_map
. boost.variant has implementation allowing various variant types acts more advanced enum. if use key, can sure map have enumerated number of types , still remain type safe. beware of issues doing this.
Comments
Post a Comment