I am in the process of creating a very simple component based game engine. I have an entity class that stores a list of components to iterate through.
The entity class also stores info like name, position, scale whatever.What I need is for each component to store a reference to the entity instance that owns it. I originally tried using the “this” keyword but it doesnt work as you cannot use it in assignments.
void Entity::addComponent(Component *theComponent){
components.push_back(theComponent);
theComponent->ownerEntity = this;
}
How can the component store a pointer to its owner?
Thanks for your help!
EDIT: The component class has pretty much nothing in it as its intended to be inherited but here is its declaration:
class Entity;
class Component
{
public:
Component();
virtual void Update();
Entity *ownerEntity;
protected:
private:
};
When Making a component if I try and access the owner entity like so:
rotation = ownerEntity->GetRotation;
I get this error:
error: argument of type 'float (Entity::)()' does not match 'float'
should be:
to call the function.