J
Joseph Turian
Okay.
So I have a class A, which contains a vector of B.
Any B item is owned by a single, unique A. Indeed, when we create A, A
creates its B items.
B would like to know which A it is contained in, without having to be
perpetually told it by being passed A when B methods are called.
How can B store its A (or some handle to A) if A stores B?
Say that B has a pointer to its A.
However, if I create a copy of an A object and delete the original, all
the B->A pointers are invalidated. Doh!
Another solution would be to have a boost::shared_ptr to A in each B.
But that doesn't work, because when you construct an item of type A and
it wants to create the items of type B, A is a plain object and hasn't
been created using the smart_ptr 'new'.
[sorry to get slightly off-topic from vanilla C++ here]
Anybody have any suggestions?
Maybe someone can suggest an appropriate pattern or way to redesign?
Thanks
Joseph
So I have a class A, which contains a vector of B.
Any B item is owned by a single, unique A. Indeed, when we create A, A
creates its B items.
B would like to know which A it is contained in, without having to be
perpetually told it by being passed A when B methods are called.
How can B store its A (or some handle to A) if A stores B?
Say that B has a pointer to its A.
However, if I create a copy of an A object and delete the original, all
the B->A pointers are invalidated. Doh!
Another solution would be to have a boost::shared_ptr to A in each B.
But that doesn't work, because when you construct an item of type A and
it wants to create the items of type B, A is a plain object and hasn't
been created using the smart_ptr 'new'.
[sorry to get slightly off-topic from vanilla C++ here]
Anybody have any suggestions?
Maybe someone can suggest an appropriate pattern or way to redesign?
Thanks
Joseph