Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdint>
- template<typename T>
- struct EnumValue {
- EnumValue()
- : value(nextValue++)
- {}
- EnumValue(uint32_t value)
- : value(value)
- {
- nextValue = value + 1;
- }
- uint32_t value;
- static uint32_t nextValue;
- };
- template<typename T>
- uint32_t EnumValue<T>::nextValue = 0;
- struct Animal {
- static EnumValue<Animal> Tiger;
- static EnumValue<Animal> Jaguar;
- static EnumValue<Animal> Hyppo;
- static EnumValue<Animal> Zebra;
- };
- EnumValue<Animal> Animal::Tiger;
- EnumValue<Animal> Animal::Jaguar;
- EnumValue<Animal> Animal::Zebra;
- EnumValue<Animal> Animal::Hyppo = 69U;
- int main()
- {
- printf("Tiger\t%d\n", Animal::Tiger.value);
- printf("Jaguar\t%d\n", Animal::Jaguar.value);
- printf("Hyppo\t%d\n", Animal::Hyppo.value);
- printf("Zebra\t%d\n", Animal::Zebra.value);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement