I have a simple problem but sometimes I'm a bit confused.
The first code:
Person *ptoPerson = new Person;
cout << ptoPerson->printMsg("Hi") << endl;
delete ptoPerson;
The second code:
Person p;
Person *ptoPerson = &p;
cout << ptoPerson->printMsg("Hi") << endl;
delete ptoPerson;
The problem occurs when deleting the pointer.
The first code works fine, and the pointer deletes, but the second code when implementing it a problem occurs at runtime.
Why the second code can't delete the pointer?
I think the pointer in the two cases is a pointer and can delete it, or am I wrong.