Why can constructor syntax not be used with the “unsigned int” type?

The syntax is Explicit type conversion (functional notation) here. According to the grammatical rule, it only works with simple type specifier or typedef specifier (i.e. a single-word type name).

(emphasis mine)

2) The functional cast expression consists of a simple type specifier or a typedef specifier (in other words, a single-word type name: unsigned int(expression) or int*(expression) are not valid), followed by a single expression in parentheses. This cast expression is exactly equivalent to the corresponding C-style cast expression.

You can change it to c-style cast expression or static_cast, or use it with typedef specifier as @Jean-FrançoisFabre suggested.

auto x1 = (unsigned int)(0);
auto x2 = static_cast<unsigned int>(0);

Quotes from the standard, $5.2.3/1 Explicit type conversion (functional notation) [expr.type.conv]

A simple-type-specifier ([dcl.type.simple]) or typename-specifier ([temp.res]) followed by a parenthesized optional expression-list or by a braced-init-list (the initializer) constructs a value of the specified type given the initializer.

And $7.1.7.2/1 Simple type specifiers [dcl.type.simple]

The simple type specifiers are

simple-type-specifier:
    nested-name-specifieropt type-name
    nested-name-specifier template simple-template-id
    nested-name-specifieropt template-name
    char
    char16_t
    char32_t
    wchar_t
    bool
    short
    int
    long
    signed
    unsigned
    float
    double
    void
    auto
    decltype-specifier
type-name:
    class-name
    enum-name
    typedef-name
    simple-template-id
decltype-specifier:
  decltype ( expression )
  decltype ( auto )

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)