Subject: Re: [boost] static in_class constants
From: John Maddock (boost.regex_at_[hidden])
Date: 2010-03-13 04:10:45


> Hi there, I'm finishing up some linker problems I have with gcc. One
> area of problems seems to be static in_class constants that I have
> declared in my header file. MSVC doesn't have problem with it but gcc
> is complaining. I'm wondering how other libs in boost are dealing with
> these problems.
>
> For instance in my new gil::io lib I define some tags in pnm_tags.hpp
> as follows:
>
> /// Defines type for image type property.
> struct pnm_image_type : property_base< uint32_t >
> {
> BOOST_STATIC_CONSTANT( type, _mono_asc = 1 ); // Monochrome ASCII
> encoding
> BOOST_STATIC_CONSTANT( type, _gray_asc = 2 ); // Gray level ASCII
> encoding
> BOOST_STATIC_CONSTANT( type, _color_asc = 3 ); // sRGB color ASCII
> encoding
> BOOST_STATIC_CONSTANT( type, _mono_bin = 4 ); // Monochrome binary
> encoding
> BOOST_STATIC_CONSTANT( type, _gray_bin = 5 ); // Gray level binary
> encoding
> BOOST_STATIC_CONSTANT( type, _color_bin = 6 ); // sRGB color binary
> encoding
> };

Two questions:

1) What is "type", it's not declared anywhere in the snippet above.
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).

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?

HTH, John.