This is simply a limitation of the language and one that has been examined by introducing generalized constant expressions.
Since the original C ++, only the static constants of a member of a class of an integral type can be initialized inline; this is the restriction of the same type as for the non-piggy type template parameters. So you can combine these two types:
struct MyTrait { static const int value = 10; }; template <int N> struct Foo; Foo<MyTrait::value> foo;
In this use, the static constant is not used odr and no definition is required. I ponder, but I can imagine that such a use was the main intention to allow inline initialization. For all other types, you probably want to have a definition anyway, so you could also put an initializer in the definition.
This, of course, is no excuse, and I believe that the introduction of constexpr seeks to correct this original limitation.
source share