cpp/language/cast operator

Enables or  from a  to another type.

Syntax
Conversion function is declared like a or member  with no parameters, no explicit return type, and with the name of the form:

@1@ Declares a user-defined conversion function that participates in all and. @2@ Declares a user-defined conversion function that participates in and  only. @3@ Declares a user-defined conversion function that is.

is a except that function and array operators  or  are not allowed in its declarator (thus conversion to types such as pointer to array requires a type alias/typedef or an identity template: see below). Regardless of typedef, cannot represent an array or a function type.

Although the return type is not allowed in the declaration of a user-defined conversion function, the of  may be present and may include any specifier other than  or the keyword, In particular, besides , the specifiers , , and  are also allowed (note that  requires a qualified name: ).

When such member function is declared in class X, it performs conversion from X to

Explanation
User-defined conversion function is invoked in the second stage of the, which consists of zero or one or zero or one user-defined conversion function.

If both conversion functions and converting constructors can be used to perform some user-defined conversion, the conversion functions and constructors are both considered by in  and  contexts, but only the constructors are considered in  contexts.

Conversion function to its own (possibly cv-qualified) class (or to a reference to it), to the base of its own class (or to a reference to it), and to the type can be defined, but can not be executed as part of the conversion sequence, except, in some cases, through  dispatch:

It can also be called using member function call syntax:

When making an explicit call to the conversion function, is greedy: it is the longest sequence of tokens that could possibly form a  :

Conversion functions can be inherited and can be, but cannot be. A conversion function in the derived class does not hide a conversion function in the base class unless they are converting to the same type.

Conversion function can be a template member function, for example, cpp/memory/auto_ptr/operator auto_ptr. See and  for applicable special rules.