2
T Y P E S
As discussed in Chapter 1, a type declares
how an object will be interpreted and used by
the compiler. Every object in a C++ program
has a type. This chapter
begins with a thorough
discussion of fundamental types and then introduces
user-defined types. Along the way, you’ll learn about
several control flow structures.
Fundamental Types
Fundamental types are the most basic types
of object and include integer,
floating-point, character, Boolean,
byte
,
size_t
, and
void
. Some refer to fun-
damental types as
primitive or
built-in types because they’re
part of the core
language and almost always available to you. These types will work on any
platform, but their features, such as size and memory layout, depend on
implementation.
Hardin once said, “To succeed, planning alone is
insufficient. One must improvise as well.” I’ll improvise.
—Isaac Asimov, Foundation
32
Chapter 2
Fundamental types strike a balance. On one hand, they try to map a
direct relationship from C++ construct to computer hardware; on the other
hand, they simplify writing cross-platform code
by allowing a programmer
to write code once that works on many platforms. The sections that follow
provide additional detail about these fundamental types.
Dostları ilə paylaş: