First of all, using the unsigned size_t type for numbers, you are likely to run into implicit promotion problems. So, it's nice to use your corresponding signed type called ptrdiff_t . Which, as it happens, is a type of result of expressing the difference of pointers.
In addition, due to changes in C ++ 11, it is usually recommended to include <stddef.h> rather than <cstddef> , i.e. write ::ptrdiff_t or just just ptrdiff_t , not std::ptrdiff_t .
Now, how to make the extern header file, bind the constant thing:
template< class Dummy > struct A_constants_ { static ::ptrdiff_t const value; }; template< class Dummy > ::ptrdiff_t const A_constants_<Dummy>::value = 42; typedef A_constants_<void> A_constants; class A : public A_constants { public:
Then you can use it as follows:
foo( A::value );
There are other ways to do this, but above all, the simplest and easiest way to get right.
Cheers and hth. - alf
source share