Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] How to assign "ft" to an si::length?
From: Terry Golubiewski (tjgolubi_at_[hidden])
Date: 2010-05-19 19:47:56


Length x = 3.0 ft did not compile, see below...

terry

#include <boost/units/systems/si.hpp>
#include <boost/units/base_units/us/foot.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/io.hpp>

#include <iostream>
#include <iomanip>

using namespace std;
using namespace boost;
using namespace boost::units;

int main() {
  typedef quantity<si::length> Length;
  static const si::length m = si::meter;
  Length x = 2.0 * m; // This works!
  cout << x << endl;

  typedef us::foot_base_unit::unit_type foot_unit;
  static const foot_unit ft;
  Length y = 3.0 * ft; // This does not compile :o(
  cout << y << endl;

  return 0;
} // main

// Compiler output...

tjg.cpp
using native typeof
tjg.cpp(21) : error C2440: 'initializing' :
      cannot convert from 'units::quantity<Unit, Y>' to
'units::quantity<Unit>'
with
[
  Unit=units::unit<
    units::list<
      units::dim<units::length_base_dimension, units::static_rational<1>>,
      units::dimensionless_type
>,
    units::heterogeneous_system<
      units::heterogeneous_system_impl<
        units::list<
          units::heterogeneous_system_dim<
            units::scaled_base_unit<
              units::us::yard_base_unit,
              units::scale<3, units::static_rational<-1>>
>,
            units::static_rational<1>
>,
          units::dimensionless_type
>,
        units::list<
          units::dim<units::length_base_dimension,
units::static_rational<1>>,
          units::dimensionless_type
>,
        units::dimensionless_type
>
>
>,
  Y=double
]
and
[
  Unit=units::si::length
]
Constructor for class 'units::quantity<Unit>' is declared 'explicit'
with
[
  Unit=units::si::length
]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net