Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] Creating a velocity unit
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2013-02-25 19:46:54


AMDG

On 02/25/2013 04:33 PM, Ryan wrote:
>>
>> at namespace scope in A.cpp:
>>
>> const metric::nautical_mile_base_unit::unit_type A::nautical_miles;
>>
>
> I don't have a .cpp. Everything is in the header. I tried doing the const
> thing after the class but it didn't work. Do I have to have a .cpp for it
> to work?
>
> Ryan
>
> //The following doesn't work.
> class A
> {
> static const metric::nautical_mile_base_unit::unit_type nautical_miles;
> static const metric::hour_base_unit::unit_type hours;
> static const decltype(nautical_miles / hours) nautical_miles_per_hour;
> }
>
> const metric::nautical_mile_base_unit::unit_type A::nautical_miles;
> const metric::hour_base_unit::unit_type A::hours;
> const decltype(nautical_miles / hours) A::nautical_miles_per_hour;
>

That will cause a different linker error.
(multiple definitions instead of undefined symbol)

It takes a bit of magic to define these in a header.
BOOST_UNITS_STATIC_CONSTANT handles it, but it only
works at namespace scope. The only to to define
them inside the class and keep it header only, is
to turn A into a template.

In Christ,
Steven Watanabe


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