I just stumbled across this: System and method for compile-time checking of units. I can't believe something so simple was awarded a patent! I've used this technique in code I've written, and my friend Dean Rettig was doing it back when I worked at Vermeer. Basically, you make a Unit template class with integer parameters that represent the exponent of units. So for distance, the value Distance would be 1. For acceleration, the value Distance would be 1 and Time would be -2. Then you define operators that only accept certain combinations of units. (You can only add the same unit type. Multiplying adds all exponent values. Etc.) Arg. Silly software patents suck.