Is there a difference between:
operator delete(some_pointer);
and
delete some_pointer;
and if so what is the difference and where one should use one and where the other version of this operator?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ironically, the
deleteoperator andoperator delete()are not the same thing.delete some_pointer;calls the destructor of the object pointed to bysome_pointer, and then callsoperator delete()to free the memory.You do not normally call
operator delete()directly, because if you do, the object’s destructor will not be called, and you are likely to end up with memory leaks.The only time you have to care about
operator delete()is when you want to do your own memory management by overridingoperator new()andoperator delete().To top it off, you should also be aware that
deleteanddelete []are two different things.