Arithmetic and Data Types - C and C++

Chapter chap4 section 15

As well as the cast mechanism for explicit type conversion, C++ also allows data type names to be used as if they were functions. This type of explicit type conversion is more typical of older program languages. For example, in C++, you could write

int(5.3)

instead of

(int)5.3

The C style cast is available in C++ because C++ is a strict superset of C, the function-like usage is more appropriate in more advanced applications.

The fact that the operators "<<" and ">>" can be used to mean two completely different things in C++ is particularly interesting. The C++ compiler decides which interpretation to apply by examining the data types of the variables associated with the operators. If the operator to the left of a "<<" or ">>" symbol is of IO stream type then input or output code is generated, otherwise shift instructions are generated.

This use of the same operator to mean different things is called operator overloading. In fact, ANSI C also has operator overloading, the operator & means something quite different (take the address) when it used a unary operator in front of variable compared with its use as a binary operator between two integers (bitwise AND).