助推器版本:1.45
编译器:Visual Studio 2008
平台:Windows 7
错误:编译以下代码时出现错误 C2440 "initializing" : cannot convert from 'boost::units::quantity' to 'boost::units::quantity' with
[
Unit=boost::units::unit>,boost::units::detail::static_power_impl<0>::apply>::type,boost::units::hogogeneous_system>>>>,
Y = double
]
和
[
Unit=myproject::types::myproject_length
]
类“boost::units::quantity”的构造函数被声明为“显式”
[
Unit=myproject::types::myproject_length
]
我不确定这里有什么问题。如果我从以下代码中删除“radii_t result =”并注释掉 IO 语句,我会得到与上面引用的相同的错误。下面是我使用的代码。感谢您在我学习 Boost Units 时的耐心等待。
Q1:这个错误的原因是什么?错误输出中的内容可以帮助您弄清楚这一点。
Q2:即使上面的错误不存在你提到它会导致维度分析失败。我想我们都同意类型是半径^-1。你如何声明一个类型被提升到正确的权力?
斯蒂芬
#include <boost/units/base_unit.hpp>
#include <boost/units/base_units/angle/radian.hpp>
#include <boost/units/io.hpp>
#include <boost/units/make_system.hpp>
#include <boost/units/physical_dimensions/length.hpp>
#include <boost/units/physical_dimensions/time.hpp>
#include <boost/units/static_constant.hpp>
#include <iostream>
namespace myproject {
namespace types {
//-------------------------------------
// Base dimensions
//-------------------------------------
struct length_base_dimension : public boost::units::base_dimension<length_base_dimension,1> {};
//-------------------------------------
// Dimensions
//-------------------------------------
struct radii_base_unit : public boost::units::base_unit<radii_base_unit, boost::units::length_dimension, 1>
{
static std::string name() { return("radii"); }
static std::string symbol() { return("r"); }
};
struct minute_base_unit : public boost::units::base_unit<minute_base_unit,boost::units::time_dimension,3>
{
static std::string name() { return ("minute"); }
static std::string symbol() { return ("min"); }
};
typedef boost::units::make_system<radii_base_unit,
minute_base_unit,
boost::units::angle::radian_base_unit >::type myproject_system_t;
typedef boost::units::unit<boost::units::length_dimension,myproject_system_t> myproject_length;
typedef boost::units::quantity<myproject_length, double> radii_t;
BOOST_UNITS_STATIC_CONSTANT(radii,myproject_length);
}
}
int main ( int, char** )
{
using namespace myproject::types;
radii_t val1 ( 5 * radii );
radii_t val2 ( 3 * radii );
radii_t result = 1.0 / ( val1 - val2 );
std::cout << result << std::endl;
return 0;
}