Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] How to multiply a quantity with a dimensionless factor
From: Marcel (minusdreidb+boost_at_[hidden])
Date: 2011-08-01 09:39:03


On 31.07.2011 19:13, Nathan Crookston wrote:
> Hi Marcel,
>
> On Sat, Jul 30, 2011 at 2:25 PM, Marcel <minusdreidb+boost_at_[hidden]> wrote:
>> Hi,
>>
>> I'm new to boost and units and hope this is not too trivial. If I try to
>> multiply a quantity with a
>> dimensionless factor like
>>
>> quantity<length> a;
>> quantity<length> b = 2.0 * b;
>>
>> I get compiler errors due to missing operator*. So I worked around this
>> by using
>>
>> quantity<length> b = quantity<dimensionless>(2.0) * b;
>>
>> But I'm wondering if there is a easier and better readable way to do
>> this?
>
> Your first example should work -- in fact, the following works for me
> on g++4 and VC10 (using boost trunk, but should work with all units
> versions):
>
> #include <boost/units/quantity.hpp>
> #include <boost/units/systems/si.hpp>
>
> using namespace boost::units;
>
> int main()
> {
> quantity<si::length> a;
> quantity<si::length> b = 2.0 * a;
>
> return 0;
> }
>
> Perhaps a compilable example, boost version, and compiler would aid
> diagnosis . . .
>
> HTH,
> Nate

Hi Nate,

thanks for your reply. The example compiles here too in fact, which made
me check my actual code more thoroughly: I had used "2" for the factor
in my actual code instead of "2.0" as stated in my example. The
differing value types seemed to cause the problem.

Regards,
Marcel


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