Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-01-01 19:08:34


>From: "Jaap Suter" <J.Suter_at_[hidden]>

> Compiling the following code on Borland 5.6:
> _________________________________
>
> template < size_t N > struct widget {};
>
> template < class T >
> struct foo
> {
> BOOST_STATIC_CONSTANT( size_t, static_constant = 42 );
> typedef widget< static_constant > bar_1;
> size_t bar_2() { return static_constant; }
> };
> _________________________________
>
> Gives the following three errors on the line that defines bar_1:
>
> Member foo<T>::static_constant cannot be used without an object
> Invalid template argument list
> Declaration terminated incorrectly
>
> The bar_2 member function compiles fine.
> Also, if I make foo a non-template class, everything compiles fine.
>
> This compiler does not result in the definition of
> BOOST_NO_INCLASS_MEMBER_INITIALIZATION so the enum-hack isn't used.
However,
> if I do in fact use the enum-hack the above code compiles fine too.
>
> Am I missing something here, or maybe Borlands static-class-constants
> behaviour is not 100% perfect....

You could say that... :) (the latter) Try fully qualifying the constant
name, as recommended here
(http://www.boost.org/more/int_const_guidelines.htm):

typedef widget< ::foo<T>::static_constant > bar_1;

I recommend that you use BOOST_STATIC_CONSTANT, as above (and not enum), as
enum doesn't always work well on this compiler (which is why static const is
used for it by this macro).

Regards,

Terje


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