Alex Shroyer
Alex Shroyer

Reputation: 3829

Uniform initialization syntax for basic types?

const int number{42};

Is this valid syntax? I can only find examples where the curly-brace initializers are used for objects or non-trivial types.

Upvotes: 2

Views: 348

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172448

The simple answer to your question is YES it is allowed and it is a valid syntax.

You may check Uniform initialization syntax and semantics by stroustrup

Also to add that as per C++98 8.5/13:

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

T x = { a };

is equivalent to

T x = a;

Upvotes: 9

Related Questions