I really need a new datatype in my application, which will only store numbers from -10 to 10. Is there a way to create a datatype with specific values, which will raise an error if the value is invalid? I used:
typedef int digit;
The thing that happens is a new datatype which is actually int is created. I also tried this:
typedef int{-10 > int value < 10} digit;
but it raised this:
exit status 1
main.cpp:3:12: error: expected unqualified-id before '{' token
typedef int{-10 > int value < 10} digit;
^
main.cpp:3:35: error: 'digit' does not name a type; did you mean 'div_t'?
typedef int{-10 > int value < 10} digit;
^~~~~
div_t