如何在Boost Unit中正确定义派生单位 [英] How to properly define a derived unit in Boost Unit
问题描述
我正在尝试在boost::units
中为si
系统的质量流量创建一个derived_dimension
.我找不到有关如何执行此简单任务的任何文档.这是我到目前为止的内容,但是在编译过程中出现错误.
I am trying to create a derived_dimension
in boost::units
for mass flow rate for si
system. I cannot find any documentation on how to do this simple task. This is what I have so far but I am getting errors during the compilation.
typedef boost::units::derived_dimension<
boost::units::mass_base_dimension, 3,
boost::units::time_base_dimension, -1
>::type mass_flow_rate_dimension;
typedef boost::units::unit<
mass_flow_rate_dimension,
boost::units::si::system
> mass_flow_rate_unit;
typedef boost::units::quantity<mass_flow_rate_unit, double> mass_flow_rate;
BOOST_UNITS_STATIC_CONSTANT(kilogram_per_seconds, mass_flow_rate);
这是我得到错误的方式:
This is how I get the error:
mass_flow_rate MFR;
quantity<mass_density> density = 1.0 * kilogram_per_cubic_meter;
quantity<si::time> Time = 1.0 * second;
quantity<volume> vol = 1.0 * cubic_meters;
MFR = density * vol / Time;
错误:C2338(is_simply_convertible :: value == true)
error: C2338 (is_simply_convertible::value == true)
推荐答案
mass_flow_rate_dimension
的尺寸错误.你拥有第三名的质量,而不仅仅是第三名
mass_flow_rate_dimension
has the wrong dimensions. You have mass to the third instead of just mass
typedef boost::units::derived_dimension<
boost::units::mass_base_dimension, 1,
boost::units::time_base_dimension, -1
>::type mass_flow_rate_dimension;
修复它.该错误仅适用于尺寸不对齐的情况.
Fixes it. That error is meant just for the case when your dimensions don't line up.
这篇关于如何在Boost Unit中正确定义派生单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!