Mixed Expressions: Hidden Dangers
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 ...
Get Core C++ A Software Engineering Approach now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.