Chapter 3 Standard Conversions

The C++ language defines conversions between its fundamental types. It also defines conversions for pointer, reference, and pointer-to-member derived types. These conversions are called “standard conversions.” (For more information about types, standard types, and derived types, see “Types” in Chapter 2, on topic .)

This chapter discusses the following standard conversions:

Integral promotions

Integral conversions

Floating conversions

Floating and integral conversions

Arithmetic conversions

Pointer conversions

Reference conversions

Pointer-to-member conversions

Note:

User-defined types can specify their own conversions. Conversion of user-defined types is covered in “Constructors” and “Conversions” in Chapter 11, on topic and topic, respectively.

The following code causes conversions (in this example, integral promotions):

long lnum1, lnum2;

int inum;

// inum promoted to type long prior to assignment.

lnum1 = inum;

// inum promoted to type long prior to

// multiplication.

lnum2 = inum * lnum2;

Note:

The result of a conversion is an l-value only if it produces a reference type. For example, a user-defined conversion declared as

MyType &operator int()

returns a reference and is an l-value. However, a conversion declared as

MyType operator int()

returns an object and is not an l-value.