Jump to content
  • Advertisement
Sign in to follow this  
Mawww

multiple inheritance hell ! argghh

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

well I have a little problem with multiple inheritance :
class Thing
{
protected:
    bool m_tchu;

    virtual void _update() = 0;
public:
    void _update() { dothings_tm(); _update(); }
};

class GoodThing : public Thing
{
protected:
    virtual void _anotherupdate() = 0;
public:
    void _anotherupdate () { if (m_tchu) { doanotherthing_tm(); _anotherupdate(); }}
};

class OpenGLThing : public Thing
{
protected:
    void _update() {...}
}

class GoodOpenGLThing : public GoodThing, public OpenGLThing
{
protected:
    void _anotherupdate() { ... }
}
gcc complain about _update being virtual in GoodOpenGLThing, probably because, even if it is defined in OpenGLThing, it is not in GoodThing. how can i achieve something similar whithout doing a lot of copy paste perhaps with templates ?

Share this post


Link to post
Share on other sites
Advertisement
a) Unless you want GoodOpenGLThing to contain two copies of Thing, you should use virtual inheritance.
class Thing {};
class GoodThing : public virtual Thing {};
class OpenGLThing : public virtual Thing {};
class GoodOpenGLThing : public GoodThing, public OpenGLThing{};


b) You have two Thing sub-objects, and only for one of them is _update() overriden. GoodThing is still an abstract class. Using virtual inheritance should fix this.

Share this post


Link to post
Share on other sites
Not trying to sound preachy or anything, but multiple inheritance is widely regarded as very, very evil. Of course, you're free to do what you like, but you class hierarchy would be cleaner, more intuitive, and easier to debug if it was designed in such a way that it didn't require multiple inheritance.

Share this post


Link to post
Share on other sites
Quote:
Original post by smitty1276
Not trying to sound preachy or anything, but multiple inheritance is widely regarded as very, very evil.


C++ doesn't have interfaces, so multiple inheritance it must often be.

Additionally, MI is generally seen as evil because of that one problem Mawww has hit. Now that he knows, he shouldn't have any more trouble with it. [smile]

Right Mawww? You won't have any more problems, will you? [evil]

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!