Class A
{
A(B& b) : mb(b)
{
}
B& mb;
};
Class B
{
B(): a(*this)
{}
A a;
}
I may encounter such a situation, it may take time, for the object contained in the container, it is necessary to use the functionality of the containers. This seems to be the best way to link to a container object in the contained object. Of course, I could do this with a pointer, so I could have a setter setB(B* b) {mb = b;}, which I could name later after I am sure that B is initialized, but I would prefer to do this with a link, which means that I need to initialize this in the constructor, hence the problem.
source
share