Exam 4 Review, Quiz 4, Convert, Aggregation+composition – Cse100 Programming With C++ 11/09

Thing which is the personal data and then we call the constructor here for it on the data that we pass in which is the first-name and lastname so why do you want to use this is that first of all.

The compiler can make this a lot faster because it can actually construct the object right where it needs to be it doesn’t have to do any copying so and we know copying is evil constructing it right where it needs to be which is pretty nice but if sure to actually do in terms of actually coding it so I can actually just call the relevant constructor of the objects that I own to make it a lot easier to construct them.

Yeah this point is not really that important unless you’re doing something like dynamic memory allocation yourself but if you if you are a person who’s doing that you’re.

Living on the edge but if you’re doing that you should have the entries in the initialization list declared in the same order as you declared the variables for reasons we won’t get into but it’s basically to clean up the memory when this object goes out of scope but the more important point is that it makes constructors a lot easier to use okay so I mentioned this example of pointers were you can have a has a relationship with a pointer so like say a.

Student object allocates a student info object on the heap then it has that object also so through a pointer.

Were were having that object through the pointer here the good thing is here is that instead of having to declare it on the stack right here allocated.

On the stack in the object if I declare it on the.

Heap then the object itself becomes smaller because all it has is a pointer to this object to the student info object in this case so having a pointer in this case makes the code a lot smaller which is useful in some circumstances yeah.

So an example of this is where if you have multiple objects which have the.

Same data then there’s no point of re declaring it in every student.

Object that you have so if for example all of the students in some class have the same zip code then there’s no point of reallocating that space in each separate object then what we can do is put all onto the heap and then have every.

Student object point to the same location so it saves.

Some space there because if I just don’t do that and put it in every single object and it’s going to be duplicated every time so pointers are useful for that circumstance yeah so aggregation is about how do you own some objects and how.

Do you and also the relationship between objects so this has a relationship but composition is about managing the.

Lifetime of the object yourself yeah so this is what I said before is when the owned object is created when you call the constructor and it’s destroyed when you call the destructor so when you call new on something you should call delete on it in the destructor as I said before but.

This is where a different type of relationship happens with regard to classes so for example.

Suppose that we wanted to make an object for each type of employee at ASU so what we would want is okay we could make a generic ASU employee object then we can make a ASU.