Ambiguity Resolution

To perform explicit conversions from one type to another, you must use casts, specifying the desired type name. Some type casts result in syntactic ambiguity. The following function-style type cast is ambiguous:

char *aName( String( s ) );

It is unclear whether it is a function declaration or an object declaration with a function-style cast as the initializer: Does the above statement declare a function returning type char * that takes one argument of type String, or does it declare the object aName and initialize it with the value of s cast to type String?

The rule in this case is that if a syntactic construct can be considered a valid function declaration, it is treated as such. Only if it cannot possibly be a function declaration—that is, if it would be syntactically incorrect—is a statement examined to see if it is a function-style type cast. Therefore, the compiler considers the statement to be a declaration of a function and treats the parentheses around the identifier s as gratuitous. On the other hand, the statements:

char *aName( (String)s );

and

char *aName = String( s );

are clearly declarations of objects, and a user-defined conversion from type String to type char * is invoked to perform the initialization of aName.