My question is how should I relate the object to each other.
I have two vectors, vector<Baby> babiesand vector<Toy> toys. Each child and each toy has a unique member int id. Thus, all children and toys are numbered from 0 to n.
Now each Child has one preferred Toy, and each Toy has a preferred Child. So far I have used pointers: Toddler has a pointer to his preferred Toy, and this toy has a pointer to a Child. (this is normal since I will never change the vectors) However, what distinguishes babies and toys from each other is their identifier, and not their location in the vector.
As I understand it, I asked about my design and found that pointers work, but in the future they can lead to problems. On the contrary, if I use the ID, I will be fine, but I will need to have access to all the vectors of babies or toys.
Is there a common practice in such a situation? Is pointers good to use? Should I write my own container that uses the identifier in an intelligent way?
Edit:
I would like to add that Ive looked at a card to tie a child and a toy. However, I determine the attitude of the child to the toy (and vice versa) at runtime. Finding this attitude is an important part of the program. So I'm not sure if I can use cards. However, I will look at it (have not used it yet). Moreover, information about the preferred toy and the child should be part of the object, and not just (exclusively) the structure of superior information.
source
share