CRTP and static member initialization

Viewed 113

When I compile the following

template <typename Derived> struct Bar 
{
     static inline constexpr int x = Derived::value;
};

struct Foo : Bar<Foo>
{
    static inline constexpr int value = 101;
};

I get a compile error using VS 2019 16.6

Source.cpp(5,47): error C2039: 'value': is not a member of 'Foo'
Source.cpp(8): message : see declaration of 'Foo'
Source.cpp(9): message : see reference to class template instantiation 'Bar<Foo>' being compiled
Source.cpp(5,1): error C2065: 'value': undeclared identifier
Source.cpp(5,1): error C2131: expression did not evaluate to a constant
Source.cpp(5,1): message : a non-constant (sub-)expression was encountered

So is it illegal to true to initialize a static from a CRTP derived class or is the compiler wrong? I certainly find the error "'value': is not a member of 'Foo'" odd as value clearly is a member.

0 Answers
Related