int main() { Dumbo dumbo(0); Dumbo dumby = dumbo; // this produces a segfault at the end of main, because delete gets called twice on the same address dumby.set(100); printf("dumbo.get() returns %d\n", dumbo.get()); printf("dumby.get() returns %d\n", dumby.get()); Dummy dummy(0); Dummy dumpy = dummy; // this produces a segfault at the end of main, because delete gets called twice on the same address dumpy.set(100); printf("dummy.get() returns %d\n", dummy.get()); printf("dumpy.get() returns %d\n", dumpy.get()); }
// copy constructor: Dummy(Dummy& dummy) : pint(new int(dummy.get())) {}