Your suggestion is what the proposal for Java does (JSR-275), e.g. they have a class Length which is the length in meters (SI) and conversion operators that take a value and a unit and convert them to meters. e.g.:
Length x = valueOf( 1, MILE );
Length y = valueOf( 1, MILE );
Length z = x.plus( y ); // OK
Area a = valueOf( 1, HECTOR );
z = x.plus( a ); /* Compile time error - you can't add a Length and an area */
Flat View: This topic has 15 replies
on 2 pages
[
«
|
12
]