Original Post
I'm making an entity system for a game in C++, and I want a function getComponent that returns a component of a specified type.
I found an example that does this when fetching a component: entitySystem->getComponent(entity)
(This isn't the intended usage, I just don't want to drag too much code from the example)
Code:
All my components are shared_ptrs, so I have to do this differently. How do I do the same thing with a shared_ptr? I want to avoid adding casts everywhere.
I found an example that does this when fetching a component: entitySystem->getComponent
(This isn't the intended usage, I just don't want to drag too much code from the example)
Code:
template<typename T> T *getComponent(Entity *e) {
return (T*)e->mComponents[T::familyId];
}
All my components are shared_ptrs, so I have to do this differently. How do I do the same thing with a shared_ptr? I want to avoid adding casts everywhere.