Clifford Heath <
no....@please.net> wrote:
> template <int unused>
> class Base
> {
> public:
> static constexpr unsigned char lengths[8] = { 1, 3, 2, 3, 4, 2, 3, 2 };
>
> void write(int x)
> { // dummy function body
> printf("%d\n", x+lengths[x]);
> }
> };
This works ok with clang:
//--------------------------------------------------------------------
template <int unused>
constexpr unsigned char Base<unused>::lengths[8];
//--------------------------------------------------------------------
If it doesn't work for your compiler for some reason, try the C++98 way:
//--------------------------------------------------------------------
template <int unused>
class Base
{
public:
static const unsigned char lengths[8];
void write(int x)
{ // dummy function body
printf("%d\n", x+lengths[x]);
}
};
template <int unused>
const unsigned char Base<unused>::lengths[8] = { 1, 3, 2, 3, 4, 2, 3, 2 };
//--------------------------------------------------------------------