$\newcommand{\defeq}{\mathrel{\mathop:}=}$

## 2006/07/18

### C++ Initializer

char change[27] = {"abcdefghijklmnopqrstuvwxyz"};


If T is a scalar type, then a declaration of the form

T x = { a };


is equivalent to

T x = a;


Arithmetic types (3.9.1), enumeration types, pointer types, and pointer to member types (3.9.2), and cv-qualified versions of these types (3.9.3) are collectively called scalar types. Scalar types, POD-struct types, POD-union types (clause 9), arrays of such types and cv-qualified versions of these types (3.9.3) are collectively called POD types.

vector<int> v = {vector<int>()};


g++ 3.4.2 不給過，但 g++ 4.1.0 給過，應該是版本演進而放寬限制（又不違背標準）。至於 Tchar[] 的情形（也就是一開始的問題），所有編譯器一致放行，或許是巧合，也可能是實作上較為方便，目前只能猜測。

An initializer for an aggregate member that is an empty class shall have the form of an empty initializer-list {}. [Example:

struct S { };
struct A {
S s;
int i;
} a = { { } , 3 };


—end example] An empty initializer-list can be used to initialize any aggregate. If the aggregate is not an empty class, then each member of the aggregate shall be initialized with a value of the form T() (5.2.3), where T represents the type of the uninitialized member.

--

yen37/18/2006 6:09 am 說：