|
|
|
|
|
by hermitdev
2728 days ago
|
|
I think your example here is pretty disingenuous because you haven't created any types, merely aliases of 'meter' and 'centimeter' that are of type int. A better example of breaking type safety would be to involve a reinterpret_cast or a C-style cast, or maybe pass something through a void*. |
|
You can created tagged structs, but you inevitably end up needing to extract the value underneath.
Regarding casts and void pointers, I think they're a slightly less dangerous case. My Spidey senses tingles whenever I need casts - static (or to a certain extent dynamic) casts are normally ok, but a reinterpret cast or a void* parameter is going to warrant a discussion and explanation in a code review.