fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <memory>
  4.  
  5. struct SmallWorld {
  6. int some_small_world_stuff;
  7. };
  8.  
  9. struct Entity {
  10. std::shared_ptr<SmallWorld> world;
  11. };
  12.  
  13.  
  14. struct Faction {
  15. std::vector<std::shared_ptr<Entity>> entities;
  16. };
  17.  
  18. struct World : public SmallWorld {
  19. std::vector<std::shared_ptr<Faction>> factions;
  20. };
  21.  
  22. int main() {
  23. auto world = std::make_shared<World>();
  24. world->some_small_world_stuff = 1337;
  25. auto fac1 = std::make_shared<Faction>();
  26. auto ent1 = std::make_shared<Entity>();
  27.  
  28. ent1->world= world;
  29. fac1->entities.emplace_back(ent1);
  30. world->factions.emplace_back(fac1);
  31.  
  32. std::cout << world->factions[0]->entities[0]->world->some_small_world_stuff << std::endl;
  33. }
Success #stdin #stdout 0s 16072KB
stdin
Standard input is empty
stdout
1337