Problem to clean vector

HEADER ----> https://pastebin.com/6CauNjLr
SOURCER ---> https://pastebin.com/fdZSdC9e

Hello

During my C ++ studies, I made this small training.

I am having a question about deleting all items from a VECTOR not using smartpointers. I made the destructors, but calling items inside the vector after the DELETE (lines 58.59 source file), they persist in memory.

Could you help me with this problem.


Thank you.
A couple issues,

1. delete p,it,ord;
Do not attempt brevity by misuse of the comma operator.
Read: https://stackoverflow.com/questions/3037655/c-delete-syntax
Do this:
1
2
3
delete p;
delete it;
delete ord;


2. (after you corrected #1)
1
2
delete ord;
ord->getItem(1);

This is undefined behavior. Your program will still compile and run, but its behavior is undefined. Do not dereference a pointer pointing to deleted data.
Last edited on
Excellent link explaining about the comma operator.

I made the corrections you suggested.

Thank you for your help.
Last edited on
Topic archived. No new replies allowed.