c++17: inner class default member initializer ignored in static inline varilables

Viewed 65

Compiling it using clang -std=c++17, and the error msg is default member initializer for '_x' needed within definition of enclosing class 'A' outside of member functions. I tried it with gcc, and got the same error msg.

It's not obvious to me why it's disallowed, and it seems that once I move the inner struct outside the enclosing class (move B out of A), it compiles fine.

#include <iostream>

class A {
struct B {
  size_t _x = 0;
};
  private:
    static inline B b = {};
};

int main(void) {
  return 0;
}
0 Answers
Related