【问题标题】:Boost: typedef for rpmBoost: rpm 的 typedef
【发布时间】:2013-07-08 22:31:44
【问题描述】:

我试图在我的代码中使用 boost::units 来定义 RoundsPerMinute 类型。但是我并不真正了解如何做到这一点。

我已经定义了一分钟

using boost::units::si::seconds;

typedef boost::units::make_scaled_unit < boost::units::si::time, boost::units::scale<60, boost::units::static_rational<1> > >::type minute;
BOOST_UNITS_STATIC_CONSTANT(minutes, minute);

typedef boost::units::quantity<minute, float> Minute;

现在可以做例如

Minute m = 5*minutes;

我现在想做的是类似于

RoundsPerMinute rpm1 = 50 * rpm;
RoundsPerMinute rpm2 = 100 / (2*minutes);
Minute m = 1/rpm2; // how many minutes does it take for one round?

但我不确定如何定义这些类型 - 坦率地说,整个 boost 文档对我来说太技术性了,我无法理解 :-( 如果有人可以帮助我定义这些类型,那就太好了。

【问题讨论】:

    标签: c++ boost boost-units


    【解决方案1】:

    一个 RPM 仅为 1/60 赫兹 - 请参阅 boost::units::si::hertz

    【讨论】:

    • 感谢您将我指向赫兹。我试过使用它,它似乎适用于基本的东西。但是我不应该能够做 1/Hertz 来获得一次迭代所需的时间吗?这会因未知运算符/而失败。
    • @Frankie:这没有意义。你做1/variable 得到另一个变量。但赫兹是一种类型(与 RPM 一样,两者都是频率类型)。
    • 当然我的意思是 boost::units::quantity freq = 2*hertz; boost::units::quantity sec = 1/freq;我希望得到 sec.value() == 0.5。
    • 啊,我好像得用1.0/freq (cmp. answer to 11087802)
    猜你喜欢
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-20
    相关资源
    最近更新 更多