Why can't we omit the capacity of an array type member variable with default initializer list in modern C++?

Viewed 56

In modern C++, member variables can be explicitly initialized. However, while we can omit the capacity of an array when defining a local array in a function with an initializer list, we cannot omit the capacity of an array member even if it has an initializer list.

For example, in the following code:

class A{
    int a[]{1,2,3,4};   // error
    int b[4]{};
    int c[4]{1,2,3,4};
};

This gives an error on the member variable a:

array bound cannot be deduced from an in-class initializer

I'm curious, why is this kind of definition not allowed?

0 Answers
Related