当我编译以下内容时
template <typename Derived> struct Bar
{
static inline constexpr int x = Derived::value;
};
struct Foo : Bar<Foo>
{
static inline constexpr int value = 101;
};
使用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
那么从CRTP派生类初始化静态变量为true非法还是编译器错误? 我当然发现错误“值”:不是“ Foo”的成员,因为值显然是成员。