|
Class A has a member, which is a pointer to class B
A {
A (B * pB1) {pB = pB1;}
B * pB;
}
If the following piece of code
B * pB = new B ();
A oA = A (pB);
delete pB;
After the last sentence, pB in oA points to an invalid address. My question is in a non-com environment, how to maintain the relationship between A and his member B pointers to ensure that the pointer B in A is always valid. In the com environment, you can use reference counting to achieve the purpose. In the environment, isn't it dangerous for one class to hold a pointer to another class? |
|