I have several objects which share a data via a pointer. The pointer parameter was sent via in the constructor functions, as follows.
class A
{
public:
Shared* pB = new Shared();
User* object1 = new User(pB);
User* object2 = new User(pB);
}
class User
{
public:
User(Shared* pB) {m_sharedB = pB};
private:
Shared* m_sharedB;
}
class Shared
{
public:
struct Account
{
int account_number;
}
void method(){...};
}
My question is related with the C++ destructor function. What happens to the member variable "m_sharedB", when object1 is deleted? Is there any problem of dangling pointer for other peers?