Classes: A Deeper Look,: 2006 Pearson Education, Inc. All Rights Reserved
Classes: A Deeper Look,: 2006 Pearson Education, Inc. All Rights Reserved
9
Classes:
A Deeper Look,
Part 1
2006 Pearson Education, Inc. All rights reserved.
2
9.1 Introduction
9.2 Time Class Case Study
9.3 Class Scope and Accessing Class Members
9.4 Separating Interface from Implementation
9.5 Access Functions and Utility Functions
9.6 Time Class Case Study: Constructors with Default
Arguments
9.7 Destructors
9.8 When Constructors and Destructors Are Called
9.9 Time Class Case Study: A Subtle Trap—Returning a
Reference to a private Data Member
9.10 Default Memberwise Assignment
9.11 Software Reusability
9.12 (Optional) Software Engineering Case Study: Starting to
Program the Classes of the ATM System
9.13 Wrap-Up
9.1 Introduction
• Integrated Time class case study
• Preprocessor wrapper
• Three types of “handles” on an object
– Name of an object
– Reference to an object
– Pointer to an object
• Class functions
– Predicate functions
– Utility functions
9.7 Destructors
• Destructor
– A special member function
– Name is the tilde character (~) followed by the class name,
e.g., ~Time
– Called implicitly when an object is destroyed
• For example, this occurs as an automatic object is destroyed
when program execution leaves the scope in which that
object was instantiated
– Does not actually release the object’s memory
• It performs termination housekeeping
• Then the system reclaims the object’s memory
– So the memory may be reused to hold new objects
*************************************************
POOR PROGRAMMING PRACTICE!!!!!!!!
t.badSetHour( 12 ) as an lvalue, invalid hour: 74
*************************************************