0
#include <iostream>
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si/length.hpp>
using namespace boost::units;
struct bu1 : base_unit<bu1, length_dimension, 2001> {};
struct bu2 : base_unit<bu2, length_dimension, 2002> {};
BOOST_UNITS_DEFINE_CONVERSION_FACTOR(bu1, bu2, double, 1.5);
#if 1
BOOST_UNITS_DEFINE_CONVERSION_FACTOR(bu2, bu1, double, 4.0);
#endif
int main(int argc, char *argv[])
{
quantity<bu1::unit_type> output(1 * bu2::unit_type());
// prints 4 or 0.67
std::cout << output.value() << std::endl;
return 0;
}
該代碼打印4
或0.666667
,具體取決於是否定義了第二個轉換因子。這應該是由設計?物理學中沒有兩個這樣的單位需要不同的轉換因子,是嗎?是通過設計還是錯誤進行雙向轉換?