Why does foo(int()) compile but foo(unsigned int()) fails to parse unless I use a type alias? [duplicate]

1 day ago 2
ARTICLE AD BOX

In C++, you cannot use "function-style" casting (e.g., T()) with types that consist of more than one keyword. The compiler sees unsigned int() and expects a standard (type)value cast or a different expression because the syntax for a function-style cast requires a single-word type name.

Explanation for @500 - Internal Server Error

int() is a functional-style cast that performs value-initialization.

When you write int(), you are explicitly telling the compiler to create a temporary integer and initialize it to its default value. For a primitive type like int, the default value is 0.

Read Entire Article