What is the difference between new/delete and malloc/free?
Related (duplicate?): In what cases do I use malloc vs
There are a few things which new does that malloc doesn’t:
new constructs the object by calling the constructor of that objectnew doesn’t require typecasting of allocated memory.So, if you use malloc, then you need to do above things explicitly, which is not always practical. Additionally, new can be overloaded but malloc can’t be.
In a word, if you use C++, try to use new as much as possible.