c++ - 如何在 Boost Unit 中正确定义派生单位

标签 c++ boost boost-units

我正在尝试在 boost::units 中为 si 系统的质量流量创建一个 derived_dimension。我找不到任何关于如何完成这个简单任务的文档。这是我目前所拥有的,但我在编译过程中遇到了错误。

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);

这是我得到错误的方式:

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)

最佳答案

mass_flow_rate_dimension 尺寸错误。你有质量到三分之一而不仅仅是质量

typedef boost::units::derived_dimension<
boost::units::mass_base_dimension, 1,
boost::units::time_base_dimension, -1
>::type mass_flow_rate_dimension;

修复它。该错误仅适用于尺寸不对齐的情况。

关于c++ - 如何在 Boost Unit 中正确定义派生单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41750974/

相关文章:

c++ - boost::program_options - 解析多个命令行参数,其中一些是字符串,包括空格和字符

c++ - 使用 boost chrono 格式化时间

c++ - 从代码中覆盖 OMP_NUM_THREADS - 真实

c++ - 为模板化类型专门化模板化函数?

c++ - 获取指向 boost::any 内容的 void* 指针

c++ - 我可以从 divide_typeof_helper 检索基本单位吗?

c++ - 类型转换 boost::units::quantity 加倍

c++ - 读取使用 ifstream 打开的文件内容

c++ - 如何在 MFC 中向 CMenu 添加子菜单?

c++ - BGL : storing vertex descriptors in a way that they won't invalidate