How is this done?

Jun 29, 2013 at 5:49am
Let's say you have a class named Girl. Then you declare:
vector<Girl> girl, girlfriend, sister, student, date;

Then later you have assignments like
girlfriend[i] = girl [a];
sister[j] = girl [a];
student[k] = girl [a];
date[m] = girl[a];

Then later down the road, you have
girl[a].age++;

Now from what I understand, though girl[a]'s age increased by 1, the ages of
girlfriend[i], sister[j], student[k], date[m] still stayed the same, right?
But what I want naturally is for all their ages to increase by 1 too, since they are all the same person, namely girl[a]. How do I do that in an automatic fashion, without going back to each one of them?
Last edited on Jun 29, 2013 at 6:01am
Jun 29, 2013 at 6:08am
You want to not copy the object, but rather have it accessible from two or more locations. Sounds like either pointers or references.
Jun 29, 2013 at 7:30am
This works. I should have thought of that from the very beginning. Now I have to change all those variables to pointers. I was hard to predict that I need to do it at the beginning.
Topic archived. No new replies allowed.