Jump to content
  • Advertisement
Sign in to follow this  

multiple inheritance

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!