Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 3. Working with C++ Data and Exp... > Mixed Expressions: Hidden Dangers

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 not with what we have seen of C++ yet). This is why the following segment of code is syntactically incorrect:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial