Objects with Functions and Arrays
Objects can be Passed Class defines type Can use as type of function or parameter
Returning an Object To return object: Use function: Make desired object Return it Use function:
Passing An Object Passing object copies the object: Main: c1 radius: 5
Passing An Object Passing object copies the object: Main: c radius: 5
Copies Generally Bad Copies Main: Are inefficient Prevent functions from modifying an object Main: c1 radius: 5
Copies Generally Bad Copies Main: Are inefficient Prevent functions from modifying an object Main: c radius: 5 c1 radius: 5
Copies Generally Bad Copies Main: Are inefficient Prevent functions from modifying an object Main: c radius: 10 c1 radius: 5
Copies Generally Bad Copies Main: Are inefficient Prevent functions from modifying an object Main: c1 radius: 5
Pass By Reference Unless you need copy, pass by reference Main: c1 radius: 5
Pass By Reference Unless you need copy, pass by reference Main: c c1 radius: 5
Pass By Reference Unless you need copy, pass by reference Main: c c1 radius: 10
Pass By Reference Unless you need copy, pass by reference Main: c1 radius: 10
Const Reference To prevent function from modifying, use const reference: Link back to original object Make changing it a compile error
Arrays Can have an array of objects CircleList radius: 2 1 2 3 4
Arrays Reference individual objects by index CircleList radius: 4 radius: 4 1 radius: 2 2 3 4
Arrays Arrays initialized with default constructor CircleList radius: 2 1 2 3 4
Arrays This makes 10 circles:
Arrays This makes 10 circles: CircleList radius: 2 1 2 3 4
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
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