0
    int main() {

    Person *pSamuel;
    pSamuel = new Person("samuel", 28, Person::Male);
    delete pSamuel;
    pSamuel = new Person("samuel", 28, Person::Male);

    return 0;
}

Hi everyone I have a quick question regarding "new" and "delete".

As you can see I set pSamuel to a new Person object, I then delete it, and then I set it to a new object, why does it point to the same address? I thought I freed the memory when I typed delete. Is this just because of the allocation algorithm is reusing the same memory for optimization? Or am I missing something about the actual delete function? Or am I missing something about create a new person object with the same data?

I appreciate any help. I just started learning c++ yesterday so go easy on me as I come from python...where I could careless about memory locations. :P

0 Answers0