Почему я не могу инициализировать неконстантный статический член или статический массив в классе?

Почему я не могу инициализировать неконстантный статический член или статический массив в классе?

class A
{
    static const int a = 3;
    static int b = 3;
    static const int c[2] = { 1, 2 };
    static int d[2] = { 1, 2 };
};

int main()
{
    A a;

    return 0;
}

компилятор выдает следующие ошибки:

g++ main.cpp
main.cpp:4:17: error: ISO C++ forbids in-class initialization of non-const static member ‘b’
main.cpp:5:26: error: a brace-enclosed initializer is not allowed here before ‘{’ token
main.cpp:5:33: error: invalid in-class initialization of static data member of non-integral type ‘const int [2]’
main.cpp:6:20: error: a brace-enclosed initializer is not allowed here before ‘{’ token
main.cpp:6:27: error: invalid in-class initialization of static data member of non-integral type ‘int [2]’

У меня два вопроса:

  1. Почему я не могу инициализировать статическиеэлементы данных в классе?
  2. Почему я не могу инициализировать статическиемассивы в классе, даже массив const?
93
задан Ben 9 November 2016 в 16:25
поделиться