Download presentation
Presentation is loading. Please wait.
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: Use function:
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: c radius: 5
6
Copies Generally Bad Copies Main: Are inefficient
Prevent functions from modifying an object Main: c1 radius: 5
7
Copies Generally Bad Copies Main: Are inefficient
Prevent functions from modifying an object Main: c radius: 5 c1 radius: 5
8
Copies Generally Bad Copies Main: Are inefficient
Prevent functions from modifying an object Main: c radius: 10 c1 radius: 5
9
Copies Generally Bad Copies Main: 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: c c1
radius: 5
12
Pass By Reference Unless you need copy, pass by reference Main: c c1
radius: 10
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 radius: 2 1 2 3 4
16
Arrays Reference individual objects by index CircleList radius: 4
radius: 4 1 radius: 2 2 3 4
17
Arrays Arrays initialized with default constructor CircleList
radius: 2 1 2 3 4
18
Arrays This makes 10 circles:
19
Arrays This makes 10 circles: CircleList radius: 2 1 2 3 4
20
Arrays This makes 10 circles: CircleList radius: 1 radius: 2 1
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 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.