Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Constructors
Desctructors
Copy constructors
Assignment operators =
Message Reminder
Approach:
getTime() returns an
object of class Time
Reminder Class
m_message is a pointer
Reminder Constructor
One possibility:
A copy is made of
the value of the pointer
Object assignment/copy
used to record time
Reminder Constructor
Reminder Constructor
Reminder Constructor
32-bits
Stack
0x04100
0x04104
0x04108
0x0410c
0x04110
0x04114
0x04118
0x0411c
0x20400
0x20404
0x20408
0x2040c
0x20410
0x20414
0x20418
0x2041c
H
o
e
?
H
?
o
?
e
l
T
r
e
0x04100
10
20
30
0x20400
????
????
0x20414
????
11
????
10
????
20
????
30
?
?
e
l
?
?
T
?
?
r
e
l
h
0
str
m_hour
m_minute
m_second
r1
m_message
m_length
m_hour
m_minute
m_second
Reminder
?
l
?
h
?
0
newly allocated
storage for message
Heap
32-bits
Stack
0x04100
0x04104
0x04108
0x0410c
0x04110
0x04114
0x04118
0x0411c
H
Y
o
e
0x20400
0x20404
0x20408
0x2040c
0x20410
H
o
e
l
T
r
e
0x04100
10
20
30
0x20400
????
0x20414
11
10
20
30
e
l
T
r
e
l
h
0
str
m_hour
m_minute
m_second
r1
m_message
m_length
m_hour
m_minute
m_second
l
h
0
Heap
Reminder Destructor
Reminder Destructor
object copying
How?
10
Object Copying
Implicit copy:
copy r2 into r3
create space for r3 then
initialise it with contents of r2
Explicit copy:
Object Copying
In parameter
passing, values are
copied silently
Return values also
implemented as a
copy of the object
11
Copy Constructor
Copy Constructor
12
Copy Constructor
Shallow Copy
r1
r2
m_message
m_length
h
e
l
l
l
o
0
m_time
m_message
m_length
m_time
Copy Constructor
Deep Copy
r1
m_message
m_length
m_time
r2
h
e
l
l
l
o
0
m_message
m_length
m_time
h
e
l
l
l
o
0
13
Copy Constructor
Assignment Operator
14
r2 copied to r
r copied to return value
Copy constructor
= operator
Destructor
15