samedi 6 octobre 2018

Having problem in dereferencing the vector

I am creating a grid game in which each box in the grid is a district and represents some people along with their specific ID.

Now I have a function here which locates where the exact person is in the grid in particular box.

Here is my function.

bool where(int id, int &row, int &col)const
{
    person* per;
    for(int i=0;i<alive.size();i++)
    {
        std::cout<<alive[i]<<std::endl; //This is just for testing the person number
        if (alive[i]->person_id == id)
        {
            p = alive[i];
            break;              
        }
    }
}

My Question: The test code std::cout<<alive[i]<<std::endl; is always printing the address of the number. I tried many things but I couldn't figure it out.

Edit: Here alive is a vector

Can anyone please help me.

Aucun commentaire:

Enregistrer un commentaire