• Advertisement
Sign in to follow this  

Multiple Inheritance or lots of pointers?

This topic is 1180 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Say I have a class called "Entity".  I want to have different types of "Entity"s: An Entity with Mesh data, an Entity with Physics data, an Entity with Skeletal Animation data, etc.

 

I could create the base Entity class, and then inherit these other Entity types.  Or I could just include a pointer to Mesh data, Physics data, Skeletal data etc. in every Entity, and I would only assign the data that the Entity actually used.  This would be beneficial since I might have an Entity that has both Mesh and Physics data, and I could avoid doing multiple inheritance.

 

I'm actually learning toward the second method, even though it wastes a little extra memory.  Is there a generally agreed upon methodology behind this?  Or any strong opinions either way?  (Or another better option that I haven't thought of?)

Share this post


Link to post
Share on other sites
Advertisement

lots of pinters members. Unless you feel like interleaving differing object in memory and not minding you cannot access them by simple index

Share this post


Link to post
Share on other sites

The proplem becomes apparent when you later want to make a FlyingMeshEntity, but have to reimplement the flying logic now...

 

The fact that "you could solve this using multiple inheritance" immediately occurred to me just highlights how bad this kind of setup is...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement