Is this list initialization an array of unknown size valid in C ++ 0x?

Is this list initialization an array of unknown size valid in C ++ 0x?

int main() { int x[]{0, 1,2,3,4}; return x[0]; }

I believe that this is true, but I would appreciate some confirmation.

If someone could quote from C ++ 0x-FCD to support their case, it would be quite helpful.

Thank!

+3
source share
2 answers

It starts from 8.5/16the first bullet to 8.5.4list-initialization and from the 8.5.4/3third bullet to 8.5.1aggregate initialization, and then 8.5.1/4says

, , , n -, ,

, = { ... } { ... }, , , direct-list-initialization, , .

, , , 8.5.4 :

struct A {
  explicit A();
};

A a[1]{};    // OK: explicit constructor can be used by direct initialization
A a[1] = {}; // ill-formed: copy initialization cannot use explicit constructor

, , ,

struct A {
  explicit A(int);
};

A a[1]{0};    // ill-formed: elements are copy initialized by 8.5.1
A a[1] = {0}; // ill-formed: same.

FCD , . , FCD , , , ( ). , , . .

+4

, , C. . , .

( ...) , sizeof(x)/sizeof(*x). , , , .

: , , , = ( , ), C ++.

0

Source: https://habr.com/ru/post/1740574/


All Articles