Chapter 19.  Types and Expressions

Table of Contents

19.1. Operators
19.1.1. Table of Operators
19.2. Evaluation of Logical Expressions
19.3. Enumerations
19.4. Signed and Unsigned Integral Types
19.4.1. Exercises: Signed and Unsigned Integral Types
19.5. Standard Expression Conversions
19.5.1. Exercises: Standard Expression Conversions
19.6. Explicit Conversions
19.7. Safer ANSI C++ Typecast operators
19.7.1. static_cast and const_cast
19.7.1.1. Exercises: static_cast and const_cast
19.7.2. reinterpret_cast
19.7.3. Why not use C-style casts?
19.8. Overloading special operators
19.8.1. Conversion Operators
19.8.2. Vectors and operator[]
19.8.3. The Function-Call operator()
19.9. Runtime Type Identification (RTTI)
19.9.1. typeid operator
19.10. Member Selection operators
19.11. Exercises: Types and Expressions
19.12. Review Questions

[ fromfile: types.xml id: types ]

Abstract

This chapter seeks to provide a deeper understanding of C++'s strong typing system, and shows how expressions are evaluated and converted.

Here we formally define some terms that we have been using. Operators are special kinds of functions that perform calculations on operands and return results. Operands are the arguments supplied to the an operator.

Operators can be thought of as ordinary functions, except that it is possible to call them using operator symbols (e.g., +, -, *, /, etc.) in addition to the longer function-call syntax.

An expression consists of a single operand, multiple operands with operators interspersed, or functions with arguments. Each expression has a type and a value. The value is obtained by applying the definitions of the operators (and/or functions) to the operands (and/or arguments).