4 ms·
I prefer having member functions that convert to a different value, and friend functions that create instances from another type: Distance d = feet(7);
by RogerL 11y ago
I prefer having member functions that convert to a different value, and friend functions that create instances from another type:
Distance d = feet(7);
d += meters(3);
std::cout << d.yards();
Distance d2 = 3; // I won't compile
This assumes that you want to mix units, not defeat it. It all ends up being very efficient; use MKS for the underlying representation. You can multiply, add, and so on, quite efficiently; the only conversions happen on input and output.