I have struggled with this design problem for some time. I will do my best to explain what I am trying to do and the various approached that I have seen, what I am trying and wh
I think you have to have one class Galaxy
, one class SolarSystem
, etc. And yours GalaxyOne
, GalaxyTwo
SolarSystemOne
, SolarSystemTwo
etc. are only different objects instantited from these classes.
class SolarSystem { /* … */ };
class Planet{ /* … */ };
class Moon{ /* … */ };
class Galaxy{ /* … */
public: // Galaxy(...?...){for (...) {read data??; solarSystem.push_back(createSolarSystem(data)); }
void AddSolarSystem(SolarSystem* ss){solarSystem.push_back(ss);}
protected:
std::vector solarSystems;
/* … */
};
....
Galaxy GalaxyOne, GalaxyTwo;
If we have no way to use this simple aproach... Lets see yours:
class GalaxyOneTwo: public GalaxyOne,
public GalaxyTwo,
public PrimitiveGalaxy{
/* … */
using PrimitiveGalaxy::solarSystems;
GalaxyOneTwo(){solarSystems.reserve(10);}
};
Here you have three private vectors: (using using
you make it direct accesible)
std::vector GalaxyOne::solarSystems;
std::vector GalaxyTwo::solarSystems;
std::vector solarSystems; //GalaxyOneTwo::solarSystems;
Is this what you need? Make it protected?