Boost logo

Boost :

Subject: Re: [boost] static in_class constants
From: Manfred Doudar (manfred.doudar_at_[hidden])
Date: 2010-03-13 14:48:07


On Sat, 13 Mar 2010 14:33:12 -0500
Christian Henning <chhenning_at_[hidden]> wrote:

> 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?
>

If declared extern you ought to be fine.

  extern const int pnm_image_type::_mono_asc;

Cheers,

-- 
Manfred

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