BOOST_STATIC_CONST

hi, I am using BOOST_STATIC_CONST for static class members of a base class. I have following situation: template <int T> class A { typedef typename MyType<T>::value_type value_type; BOOST_STATIC_CONST(typename value_type::some_type, MY_CONSTANT = 0); }; template <int T> class B : public A<T> { typedef A<T> Base; typedef typename Base::value_type value_type; BOOST_STATIC_CONST(typename value_type::some_type, MY_CONSTANT = Base::MY_CONSTANT); }; or template <int T> class B : public A<T> { typedef A<T> Base; typedef typename Base::value_type value_type; using Base::MY_CONSTANT; }; for both cases I got a linker error: /usr/bin/ld: Undefined symbols: B<0>::MY_CONSTANT what am I doing wrong? I am using darwin gcc4.0.1 and Boost from CVS thanks a lot! michael

Michael Held wrote:
hi,
I am using BOOST_STATIC_CONST for static class members of a base class. I have following situation:
template <int T> class A { typedef typename MyType<T>::value_type value_type; BOOST_STATIC_CONST(typename value_type::some_type, MY_CONSTANT = 0); };
template <int T> class B : public A<T> { typedef A<T> Base; typedef typename Base::value_type value_type; BOOST_STATIC_CONST(typename value_type::some_type, MY_CONSTANT = Base::MY_CONSTANT); };
or
template <int T> class B : public A<T> { typedef A<T> Base; typedef typename Base::value_type value_type; using Base::MY_CONSTANT; };
for both cases I got a linker error: /usr/bin/ld: Undefined symbols: B<0>::MY_CONSTANT
what am I doing wrong? I am using darwin gcc4.0.1 and Boost from CVS
In theory you are doing nothing wrong, linker errors like that should only occur if you take the address of the constant: in that case you would need an out-of-line definition as well: template<int T> type_of_constant B<T>::MY_CONSTANT; I'll leave it to you to figure out what "type_of_constant" is ! :-) You would need to wrap this in #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION #endif if you want the code to be portable, but if you really are taking the constant's address then it won't be portable to older compilers anyway (since you can't take the address of an enum which is what BOOST_STATIC_CONSTANT uses in those cases). HTH, John.
participants (2)
-
John Maddock
-
Michael Held