I have read that if we have pointers inside our class then we need to implement our own copy constructor; otherwise, two classes will have pointers pointing to the same memory location, and calling delete on one of them makes the other null as well. I am trying to simulate the above condition by writing a code like this:
class A
{
private:
int *p;
public:
A()
{
p = new int(10);
}
~A()
{
delete p;
cout << "Calling destructor" << endl;
}
};
int main(int argc, char **argv)
{
A a;
A aa = a;
}
I am expecting some exception to be thrown as I have not explicitly declared my copy constructor and I am using pointers as well. But program runs perfectly. Can anybody please suggest a modification so that I am able to understand under what condition exception will occur?