gpt4 book ai didi

c++ - "incomplete type"关于使用 C++ 单位 units::compose

转载 作者:行者123 更新时间:2023-11-28 08:07:33 32 4
gpt4 key购买 nike

我正在使用 Calum Grant 的 C++ 单元库 http://calumgrant.net/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> >'

缺少什么?

最佳答案

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

namespace units {

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

namespace values {
typedef value<double, units::fpm> fpm;
}

}

关于c++ - "incomplete type"关于使用 C++ 单位 units::compose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9959298/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com