I have a simple question that I am not 100% sure on.
Let us say I have a Entity class, that handles objects on the screen. Let us say the Entity class has two float variables, 'x' and 'y' (aka coordinates). Also let us say the entity I am passing has already been declared and is in memory.
I have another class that handles camera movement. It requires an entity to center on. The entity that it is centered on can changed, so I need to use a pointer here I believe. The only thing I do here is grab the X and Y variables when needed. Nothing is changed here.
I've defined it as
void StarField::ChangeFollowEntity(Entity* newFollowEntity) {
followEntity = newFollowEntity;
}
where followEntity is also an Entity class. I would call ChangeFollowEntity(..) to change the entity. Is this actually correct?
I've also seen however this:
void StarField::ChangeFollowEntity(Entity newFollowEntity) {
followEntity = &newFollowEntity;
}
In both cases followEntity is defined as Entity* followEntity; .. What does the second example exactly do here? From what I understand, & would typically be used as a reference type. Maybe it is incorrect to do to begin with.
I am pretty sure I shouldn't be using a reference in this case because the followEntity changes, which references I believe cannot change and must be defined.
So my question is, is my first example correct and the right way to do it? What does the second example do exactly?