Boost logo

Boost :

Subject: Re: [boost] static in_class constants
From: Christian Henning (chhenning_at_[hidden])
Date: 2010-03-13 14:33:12


Hi Mateusz,

On Sat, Mar 13, 2010 at 1:23 PM, Mateusz Loskot <mateusz_at_[hidden]> wrote:
> Christian Henning wrote:
>>> 2) I notice you saying that you're getting linker errors - that
>>> should only happen if you're taking the address of the constants
>>> somewhere - if that's a use case that you want to support, then you
>>> need a definition for the constants somewhere - suitably guarded by
>>> the right Boost.Config macros (sorry can't remember what off the
>>> top of my head).
>>
>> I'm getting a compiler error with gcc 3.4.5. The compiler that comes
>> with MinGW.
>
> Is it compiler error or linker error?

I don't remember off the top of my head. It might have been a linker
error, though. Don't have access right now to gcc.

>
> This can be fixed, inconveniently, by adding external definition:
>
> struct pnm_image_type : property_base<int>
> {
>    typedef pnm_image_type self_type;
>    BOOST_STATIC_CONSTANT( type, _mono_asc  = 1 );
> };
> const int pnm_image_type::_mono_asc;

Wouldn't that create multiple instances when including this header
file more than one time?

>
>
>>> And finally, given that your constants look like enumerated values,
>>> is there actually a pressing need not to make them an anonymous
>>> enumerated type in this case?
>>
>> I know about using enums for such a case. But it used to be a matter
>> of taste since MS compiler works just fine.
>
> Works well with in-class definition of constants from Visual C++ 7.1
> (2003), but previous versions do not support it such definitions at all.

Don't think we need to worry about any Visual C++ older than 7.1. My
worries are more with gcc.

Regards,
Christian


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk