I am learning shallow copy and deep copy so I wrote the below code myself that tries to deallocate the same memory block twice. But surprisingly the program isn't crashing. I don't know where it's going wrong.
#include<iostream>
using namespace std;
class Demo {
private:
int *data;
public:
Demo(int d): data {new int} {
*data = d;
}
Demo(const Demo &src): data {src.data} {}
~Demo() {
delete data;
}
};
int main(void) {
Demo d1(100);
Demo d2 {d1};
return 0;
}