The assignment operator (=) can be used to assign an object to another object of the same type.
- Assigning objects
- Assignment operator (=)
- Can assign one object to another of same type
- Default: memberwise assignment
- Each right member assigned individually to left member
- Passing, returning objects
- Objects passed as function arguments
- Objects returned from functions
- Default: pass-by-value
- Copy of object passed, returned
- Copy constructor; Copy original values into new object
Member wise assignment can cause serious problems when used with a class whose data members contain pointers to dynamically allocated storage.
Figure 19:
Default memberwise assignment. (part 1 of 2)
|
Figure 20:
Default memberwise assignment. (part 2 of 2)
|
2004-07-01