Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
C++ is a strongly typed language. This means that if the context requires a value of one type, it is a syntax error to use a value of another type instead. This is an important principle that allows the programmers to weed out errors with less effort: Instead of hunting the errors down in the laborious process of run-time testing, the programmer is told by the compiler that the code is incorrect.
Consider, for example, the TimeOfDay type that I used in Chapter 2. It is a composite type (not a scalar) with two integer components. Notation exists for setting the field values and for accessing them, and that is all. You cannot add 2 to a TimeOfDay variable or compare it with another TimeOfDay variable (at least not with what we have seen of C++ yet). This is why the following segment of code is syntactically incorrect: