First of all your understanding on dangling pointers is wrong. Here there is no dangling pointer. Below I have given an example for dangling pointer
class A
{
int* pnData;
public:
A()
{
pnData = new int;
}
};
A* paObj = new A;
:
:
delete paObj; paObj = 0;
Here you are deleting the pointer paObj, which makes the pointer pnData a dangling pointer.
Because after deleting paObj, there is no way you can delete pnData which makes pnData a dangling pointer.
in your code example both the pointers are refering the same memory. so deleting one will defently delete the other.
To avoid this you have to create separate objects (both the objects using new)and assign the object members using an overloaded assignment operator