multiple inheritance hell ! argghh

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

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 on other sites
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 on other sites
I didn't know about virtual inheritance ! it works now. thank you.

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 on other sites
Quote:
 Original post by smitty1276Not 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]

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• Forum Statistics

• Total Topics
634091
• Total Posts
3015435
×