I can´t understand why this program crashes.
In main(), I declare char *name = new char; and pass it as argument in the Person constructor.
When deleting the Person pointer in main(), the Person destructor is beeing called and the name attribute (which is a pointer) pointing at the char, I assume, is also beeing deleted. But why does it crash?
You can only delete a pointer that is, or has the same value as, a pointer that was returned by a new.
You are trying to delete a pointer that was not returned by a new.
The pointer you're trying to delete is pointing to the char allocated by this line of code: char name = 'b';
and the pointer itself was created like this: p->setName(&name);
and then stored like this: this->name = name;
The pointer thus is not pointing at memory allocated using new.