lii
An Overture to C Programmers
sets the
version
, which is an invariant, to
9000
. The
destructor is the second
method
v
. Whenever
Hal
is about to be deallocated, it prints
"Stop, Dave."
to the console. (Getting
Hal
to sing “Daisy Bell” is left as an exercise to the
reader.)
The compiler makes sure the constructor and destructor are invoked
automatically for objects with static, local, and thread local storage dura-
tion. For objects with dynamic storage duration, you use the keywords
new
and
delete
to replace
malloc
and
free
, Listing 22 illustrates.
#include
struct Hal {
Dostları ilə paylaş: