2

I tried to init char[][] static public field in class but in another function this field is undefined. How I use consexpr or exists another method to init static (dictionary) array?

class A {
    public:
        constexpr static char dict[][3] = {
            "a",
            "bb"
        };

        void print() {
            printf(A::dict[1]);
        }
};

int main() {
    A a;
    a.print();
    return 0;
}

10 undefined reference to `A::dict'

user2010633
  • 121
  • 1
  • 8

1 Answers1

4

The definition needs to go outside the class, while the initializer belongs inside the class.

constexpr char A::dict[][3];