Sign in to follow this  

C++ Polymorphism - Multiple Inheritance Dilemma (SOLVED)

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

I am (obviously) having a problem with multiple inheritance in C++... What I'm trying to do is create a few sub classes (containers, ex. BgContainer, TileContainer, etc), and then tie those containers into a class using multiple inhertance (ex. CRoom). I don't need any spiffy abstract management (virtual functions), just simply tying the functions (all have different names) into a class I can call them from. Problem is, I get the compiler error basically stating that it can not derrive class A from class B (it is a 'non accessible base'). This is the problem I'm describing:
[source lang='cpp']class BgContainer {
 //Data
 ...
 //Methods
 BgContainer();
 bool BgRegister(...);
 ...
};
class TileContainer {
 ...
 TileContainer();
 bool TileRegister(...);
 ...
};
...
//Insert generic container here
...
//Tie them into one class
class CRoom : public BgContainer, public TileContainer, ... { //<< Error was here. Needed 'public' keyword for each base def
 //More specific data/functions (all names are different still)
};



Of course, through the method I'm using, that isn't working. The next soloution is have one container be the 'base' container, make a second that derrives from the base, make a third that derrives from the third, ..., and have a final tie-in class derrive from the previous container. Only problem with that is, I want to use the containers in different areas (not just for the room, ex. TileSet : public TileContainer), and the first multiple inheritance attempt I tried didn't work... Does anyone know of any good methods to try and acheive this? Any help would be greatly appreciated. NOTE: If nothing else works, I can simply put the containers inside the room class (as variables), instead of derriving from them. This, however, will make me have to call the variable and then the room.

Share this post


Link to post
Share on other sites
Ah, I found my problem!
Thanks Promit, I wasn't exactly working with a diamond stucture (the containers don't derrive from anything, and if they did, they'd be templated), but the link you referred me to pointed out that one needed to type 'public' for each derrived base!
Gragh, I feel stupid for not thinking of that earlier.

And I'll be sure to keep this in mind. Thanks again.

Share this post


Link to post
Share on other sites

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