Легенда:
новое сообщение
закрытая нитка
новое сообщение
в закрытой нитке
старое сообщение
|
- Напоминаю, что масса вопросов по функционированию форума снимается после прочтения его описания.
- Новичкам также крайне полезно ознакомиться с данным документом.
[C++] ISO/IEC 14882 Раздел 8.5.1 Aggregates [dcl.init.aggr] [update] 18.11.05 11:48 Число просмотров: 2419
Автор: amirul <Serge> Статус: The Elderman Отредактировано 18.11.05 12:03 Количество правок: 1
|
> void func() > { > a inst = {0};
Тогда уж лучше
a inst = {};
> ... > } > > Кстати, a inst = {1,1} тоже вполне работает . Так вот, не > могу найти в стандарте С++ это дело. Где про это > растолковано? Это и есть мой вопрос.
[skipped]
7 If there are fewer initializers in the list than there are members in the aggregate, then each member not explicitly initialized shall be value-initialized (8.5). [Example:
struct S { int a; char* b; int c; };
S ss = { 1, "asdf" };
initializes ss.a with 1, ss.b with "asdf", and ss.c with the value of an expression of the form int(), that is, 0. ]
[skipped]
Ну и на всякий случай раздел 8.5 Initializers [dcl.init]
[skipped]
5 To zero-initialize an object of type T means:
— if T is a scalar type (3.9), the object is set to the value of 0 (zero) converted to T;
— if T is a non-union class type, each nonstatic data member and each base-class subobject is zeroinitialized;
— if T is a union type, the object’s first named data member89) is zero-initialized;
— if T is an array type, each element is zero-initialized;
— if T is a reference type, no initialization is performed.
To default-initialize an object of type T means:
— if T is a non-POD class type (clause 9), the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);
— if T is an array type, each element is default-initialized;
— otherwise, the object is zero-initialized.
To value-initialize an object of type T means:
— if T is a class type (clause 9) with a user-declared constructor (12.1), then the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);
— if T is a non-union class type without a user-declared constructor, then every non-static data member and base-class component of T is value-initialized;
— if T is an array type, then each element is value-initialized;
— otherwise, the object is zero-initialized
[skipped]
> Спасибо.
--------------
POD, если кто вдруг не знает - это Plain Old Data. То бишь структура в старом C-шном понимании (без методов, конструкторов и прочей фигни)
|
|
|