Sign in to follow this  

Multiple Inheritance or lots of pointers?

This topic is 1107 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

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

This topic is 1107 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this