3 ms·
100% agree. I love C++ for allowing me to do things like: CInches in1, in2, in3; // basically just floating points CCm cm1; // basically just float
by GnarfGnarf 4y ago
100% agree. I love C++ for allowing me to do things like:
CInches in1, in2, in3; // basically just floating points
CCm cm1; // basically just floating points
in1 = in2 + in3; // no compilation error
in1 = in2 + cm1; // compilation error
in1 = in2 * in3; // compilation error
in1 = 2. * in2; // no compilation error
float foo(CInches *);
foo(cm1); // compilation error
Obviously there's a lot of code behind "CInches", but it catches so many errors.
Which other languages also support this?
- xigoi 4y ago> Which other languages also support this? Haskell and related languages have distinct types; so does Nim. But even if there's no direct language support, you can always emulate them by having a compound type (record, struct, class, whatever you call it) with one field.