Download presentation
Presentation is loading. Please wait.
Published byClyde Gray Modified over 8 years ago
1
Objects with Functions and Arrays
2
Objects can be Passed Class defines type – Can use as type of function or parameter
3
Returning an Object To return object: – Make desired object – Return it Use function:
4
Passing An Object Passing object copies the object: Main: c1 radius: 5
5
Passing An Object Passing object copies the object: Main: c1 radius: 5 c
6
Copies Generally Bad Copies – Are inefficient – Prevent functions from modifying an object Main: c1 radius: 5
7
Copies Generally Bad Copies – Are inefficient – Prevent functions from modifying an object Main: c1 radius: 5 c
8
Copies Generally Bad Copies – Are inefficient – Prevent functions from modifying an object Main: c1 radius: 5 c radius: 10
9
Copies Generally Bad Copies – Are inefficient – Prevent functions from modifying an object Main: c1 radius: 5
10
Pass By Reference Unless you need copy, pass by reference Main: c1 radius: 5
11
Pass By Reference Unless you need copy, pass by reference Main: c1 radius: 5 c
12
Pass By Reference Unless you need copy, pass by reference Main: c1 radius: 10 c
13
Pass By Reference Unless you need copy, pass by reference Main: c1 radius: 10
14
Const Reference To prevent function from modifying, use const reference: Link back to original object Make changing it a compile error
15
Arrays Can have an array of objects CircleList 0 radius: 2 1 2 3 4
16
Arrays Reference individual objects by index CircleList 0 radius: 4 1 radius: 2 2 3 4
17
Arrays Arrays initialized with default constructor CircleList 0 radius: 2 1 2 3 4
18
Arrays This makes 10 circles:
19
Arrays This makes 10 circles: CircleList 0 radius: 2 1 2 3 4
20
Arrays This makes 10 circles: CircleList 0 radius: 1 1 radius: 2 2 radius: 3 3 radius: 4 4 radius: 5
21
Arrays Use initialization list to prevent filling with default objects: CircleList 0 radius: 1 1 radius: 2 2 radius: 3 3 radius: 4 4 radius: 5 Call 1-arg constructor to make anonymous object
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.