3 ms·
C++ can do an excellent job of catching unit mismatches at compile time. We have developed classes that support this: cInches in1, in2, in3; // basically
by GnarfGnarf 6y ago
C++ can do an excellent job of catching unit mismatches at compile time. We have developed classes that support this:
cInches in1, in2, in3; // basically 'floats'
cCm cm1; // floats
void foo(cInches);
in1 = in2 + in3; // OK
in1 = in2 + cm1; // compile error
in1 = in2 * in3; // compile error: square inches are not inches
in1 = in2 / in3; // compile error
float x = in2 / in3; // OK
foo(in1); // OK
foo(cm1); // compile error
Classes like these have made the code much more readable, maintainable and reduce errors.