Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 937
Alex Shroyer Avatar asked Jun 04 '26 11:06

Alex Shroyer


1 Answers

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;
like image 175
Rahul Tripathi Avatar answered Jun 07 '26 01:06

Rahul Tripathi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!