problem with boost units
the following small example fails to compile and points to error in
assignment. For the life of me I can't figure why this should fail.
Any help appreciated.
Robert Ramey
// include headers to implement output operations for quantities with units
#include <iostream>
#include
On September 17, 2015 1:31:28 AM EDT, Robert Ramey
the following small example fails to compile and points to error in assignment. For the life of me I can't figure why this should fail. Any help appreciated.
Robert Ramey
// include headers to implement output operations for quantities with units #include <iostream> #include
#include
int main(){ boost::units::si::volume fuel_capacity; fuel_capacity = 9.0f * boost::units::si::cubic_meters; ------------------^ std::cout << " " << fuel_capacity << "\n"; return 0; }
It's because you are trying to assign a quantity to a dimension. quantity<volume> my_vol = 9f * cubic_meters; Or if your compiler has auto support. auto my_vol = 9f * cubic_meters; See the examples for clarification as well. HTH
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Sent from my Android device with K-9 Mail. Please excuse my brevity.
On 17/09/2015 21:17, Michael wrote:
It's because you are trying to assign a quantity to a dimension.
quantity<volume> my_vol = 9f * cubic_meters;
Or if your compiler has auto support.
auto my_vol = 9f * cubic_meters;
See the examples for clarification as well.
Note that (at least in my limited experience) it's best to avoid using "auto" with Boost.Units, as this does not properly collapse scaled units and you can get even weirder errors. Stick to using quantity<T> explicitly (or a convenience typedef for it).
participants (3)
-
Gavin Lambert
-
Michael
-
Robert Ramey