【问题标题】:"incomplete type" on using C++ units units::compose使用 C++ 单元的“不完整类型”units::compose
【发布时间】:2012-04-15 02:27:08
【问题描述】:

我正在使用 Calum Grant http://calumgrant.net/units/ 的 C++ Units 库来管理表示长度或速度的值。

现在我需要这个库未指定的单位,即英尺每分钟。根据http://calumgrant.net/units/units.html,您可以像这样制作新单位:

typedef units::compose< units::units::m, units::pow<units::units::s, -1> > meters_per_second;

但是这个例子不起作用。如果我指定

typedef units::compose< units::units::foot, units::pow<units::units::minute, -1> > 
feet_per_minute;
feet_per_minute vertical_speed(12);

我收到以下编译错误(在 Mac 上使用 gcc 4.2.1)

error: variable 'feet_per_minute vertical_speed' has initializer but incomplete type

使用 clang 3 编译时出现此错误

error: implicit instantiation of undefined template 'units::compose<units::scale<units::scale<units::scale<units::units::m, 100, 1>, 100, 254>, 1, 12>, units::pow<units::scale<units::units::s, 1, 60>, -1, 1> >'

缺少什么?

【问题讨论】:

    标签: c++ templates units-of-measurement


    【解决方案1】:

    嗯,我刚刚发现了问题。存在“单位”,并且存在这些单位的“价值”。所以正确的定义如下:

    namespace units {
    
    namespace units {
         typedef compose< foot, pow<minute, -1> > fpm;
    }
    
    namespace values {
        typedef value<double, units::fpm> fpm;
    }
    
    }
    

    【讨论】:

      【解决方案2】:

      尝试每秒英尺​​数。看看是否可行,然后重新发布

      【讨论】:

        猜你喜欢
        • 2013-12-01
        • 2016-10-06
        • 1970-01-01
        • 2013-09-15
        • 2012-11-18
        • 2013-01-19
        • 2013-09-27
        • 1970-01-01
        • 2016-12-07
        相关资源
        最近更新 更多