I would like to define several names for the same type and have the compiler distinguish between them.My motivation is that different int variables could represent very different units, and I would like the compiler to catch errors in units.typedef int Speed does not generate any warnings, when assigning to Speed from int. One possible solution is using an enum. Furthermore, the enum hack does not let me specify the underlying representation e.g. uint8_t.Is what I am trying to do a bad practice? How do I achieve it in C++? Edit:Grim. I tied using enum Speed {};. error: invalid conversion from 'int' to 'Speed' [-fpermissive] error: no match for 'operator+=' in 'a += b'Those are just a couple of errors I encountered. Enums can't be the right way.I will think about structs, and if in my case some members and predefined operators can actually make the rest of the code cleaner.Hmm, here is quite some research, to the point of making my question a duplicate.
How to define different names for the same type and have the compiler check them?
c++11;type safety