$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] static in_class constants
From: Christian Henning (chhenning_at_[hidden])
Date: 2010-03-15 10:26:56
Hi Manfred,
>>
>> Wouldn't that create multiple instances when including this header
>> file more than one time?
>>
>
> If declared extern you ought to be fine.
>
> extern const int pnm_image_type::_mono_asc;
>
>
Mhmm, the Windows compiler doesn't like that. This is what I tried in
one of my header files. BTW, my lib is header only.
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
};
extern const int pnm_image_type::_mono_asc;
extern const int pnm_image_type::_gray_asc;
extern const int pnm_image_type::_color_asc;
extern const int pnm_image_type::_mono_bin;
extern const int pnm_image_type::_gray_bin;
extern const int pnm_image_type::_color_bin;
The error is:
error C2720: 'boost::gil::pnm_image_type::_mono_asc' : 'extern '
storage-class specifier illegal on members
error C2734: 'boost::gil::pnm_image_type::_mono_asc' : const object
must be initialized if not extern
[snip]
Olivier Tournaire suggested to use boost::mpl like this:
struct pnm_image_type : property_base< uint32_t >
{
typedef boost::mpl::integral_c<type,1> _mono_asc;
typedef boost::mpl::integral_c<type,2> _gray_asc;
typedef boost::mpl::integral_c<type,3> _color_asc;
typedef boost::mpl::integral_c<type,4> _mono_bin;
typedef boost::mpl::integral_c<type,5> _gray_bin;
typedef boost::mpl::integral_c<type,6> _color_bin;
};
This seems to work with my gcc and though I will go with this
solution. All, I'm interested in is the value and not the actual class
member or address to the member.
Regards,
Christian