C++ Polymorphism - Multiple Inheritance Dilemma (SOLVED)

Started by
1 comment, last by deadimp 18 years, 3 months ago
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.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
Advertisement
Make sure you use virtual inheritance if you're building any sort of diamond hierarchy. In fact, read everything on this page.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
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.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire

This topic is closed to new replies.

Advertisement