Jump to content
  • Advertisement
Sign in to follow this  
ogl5

multiple inheritance

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

Advertisement
Say you have a game that has different types of characters. There are say, two races humans and humanoids.

There are two classes HUMANS and HUMANOIDS with the necessary attributes in them.

Then you have certain types of NPCs : wizards, soldiers, etc. So you create classes WIZARD, SOLDIER etc. WIZARD will have attributes like SPELL STRENGTH etc.

Now to create a HUMAN WIZARD class you inherit both HUMAN and WIZARD classes into a new class HUMAN WIZARD. This is multiple inheritance.

The advantages of using multiple inheritance is that it removes redundancy. That is, the attributes of human need not be repeated in the classes HUMAN WIZARD and HUMAN SOLDIER, they are specified only once: in the class HUMAN and are inherited.

The disadvantage is of course that multiple inheritance causes ambiguity as the same attribute can be inherited from more than one class.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!