0

I created a vector (of civilizations), a list (of villagers), and a menu. If I add an object of civilization to the vector it works, but when I add an object of villagers I want it to be saved in the selected civilization, (so when I ask for the villagers of "m" and "n" or whatever civilization, it should show different villagers) but when using it the vector and the list are separated. How can I combine them, so when I add objects to a list in the position of the vector, that information is shown just when asked, when the position is called?

Here is my class villager

class Aldeano
{
string nombre;
unsigned int edad;
string genero;
int salud;

public:
Aldeano();
(. . . )

Here is my class civilization

class Civilizacion
 {
private:
string name;
int x;
int y;

list<Aldeano> aldeanos;
public:
Civilizacion();
( . . . )

Here is my vector

class VideoGame
{
private:
string username;
vector<Civilizacion>arreglo;
Menu menu;
public:
VideoGame();
(. . .)

This is when I add villagers the menu

if(opc=="1"){
        Aldeano a = capturarAld();
        civilizacion.frontAld(a);
    }else if(opc=="2"){
        Aldeano a = capturarAld();
        civilizacion.backAld(a);
    }else if(opc=="0"){
        break;
    }

These are the functions it's calling

Aldeano frontAld(const Aldeano &a)
{aldeanos.push_front(a);
return a;}

Aldeano backAld(const Aldeano &a)
{aldeanos.push_back(a);
return a;}

Which I think it is logical that it is separated from the vector, but I have no idea how to get that into a certain position of the vector.

  • Whats the definition for civilizacion? If it is something like Civilizacion civilizacion = arreglo[n] then you have an independent copy – Caleth Apr 11 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy