Boost Units version: 1.45
Compiler: Visual Studio 2008
Platform: Windows 7
Error: When compiling the following code I get an error 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
]
and
[
Unit=myproject::types::myproject_length
]
Constructor for class 'boost::units::quantity' is declared 'explicit' with
[
Unit=myproject::types::myproject_length
]
I am not sure what is wrong here. If I remove the "radii_t result =" from the following code and comment out the IO statement I get the same error as previously quoted above. Below is the code I used. I appreciate your patience as I learn Boost Units.
Q1: What is the reason for this error? What in the error output helped you to figure that out.
Q2: Even if the above error did not exist you mentioned that it would fail the dimensional analysis. I think we both agree the type would be radii^-1. How do you declare a type to be raised to the correct power?
Stephen
#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;
}