Search code examples
c++c++11uniform-initialization

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.


Solution

  • 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;